You don’t need
bun create
to use Bun. You don’t need any configuration at all. This command exists to make getting started a bit quicker and easier.Template a new Bun project with
bun create
. This is a flexible command that can be used to create a new project from a React component, a create-<template>
npm package, a GitHub repo, or a local template.
If you’re looking to create a brand new empty project, use bun init
.
From a React component
bun create ./MyComponent.tsx
turns an existing React component into a complete dev environment with hot reload and production builds in one command.
🚀 Create React App Successor —
bun create <component>
provides everything developers loved about Create React App, but with modern tooling, faster builds, and backend support.How this works
When you runbun create <component>
, Bun:
- Uses Bun’s JavaScript bundler to analyze your module graph.
- Collects all the dependencies needed to run the component.
- Scans the exports of the entry point for a React component.
- Generates a
package.json
file with the dependencies and scripts needed to run the component. - Installs any missing dependencies using
bun install --only-missing
. - Generates the following files:
${component}.html
${component}.client.tsx
(entry point for the frontend)${component}.css
(css file)
- Starts a frontend dev server automatically.
Using TailwindCSS with Bun
TailwindCSS is an extremely popular utility-first CSS framework used to style web applications. When you runbun create <component>
, Bun scans your JSX/TSX file for TailwindCSS class names (and any files it imports). If it detects TailwindCSS class names, it will add the following dependencies to your package.json
:
package.json
bunfig.toml
to use Bun’s TailwindCSS plugin with Bun.serve()
bunfig.toml
${component}.css
file with @import "tailwindcss";
at the top:
MyComponent.css
Using shadcn/ui
with Bun
shadcn/ui
is an extremely popular component library tool for building web applications.
bun create <component>
scans for any shadcn/ui components imported from @/components/ui
.
If it finds any, it runs:
terminal
shadcn/ui
itself uses TailwindCSS, bun create
also adds the necessary TailwindCSS dependencies to your package.json
and configures bunfig.toml
to use Bun’s TailwindCSS plugin with Bun.serve()
as described above.
Additionally, we setup the following:
tsconfig.json
to alias"@/*"
to"src/*"
or.
(depending on if there is asrc/
directory)components.json
so that shadcn/ui knows its a shadcn/ui projectstyles/globals.css
file that configures Tailwind v4 in the way that shadcn/ui expects${component}.build.ts
file that builds the component for production withbun-plugin-tailwind
configured
bun create ./MyComponent.jsx
is one of the easiest ways to run code generated from LLMs like Claude or ChatGPT locally.
From npm
terminal
create-<template>
package from npm. The following two commands will behave identically:
terminal
create-<template>
package for complete documentation and usage instructions.
From GitHub
This will download the contents of the GitHub repo to disk.terminal
terminal
- Download the template
- Copy all template files into the destination folder
- Install dependencies with
bun install
. - Initialize a fresh Git repo. Opt out with the
--no-git
flag. - Run the template’s configured
start
script, if defined.
By default Bun will not overwrite any existing files. Use the
--force
flag to overwrite existing files.From a local template
Unlike remote templates, running
bun create
with a local template will delete the entire destination folder if it already exists! Be careful.$HOME/.bun-create/<name>
: global templates<project root>/.bun-create/<name>
: project-specific templates
You can customize the global template path by setting the
BUN_CREATE_DIR
environment variable.$HOME/.bun-create
and create a new directory with the desired name of your template.
package.json
file in that directory with the following contents:
package.json
bun create foo
elsewhere on your file system to verify that Bun is correctly finding your local template.
Setup logic
You can specify pre- and post-install setup scripts in the"bun-create"
section of your local template’s package.json
.
package.json
Field | Description |
---|---|
postinstall | runs after installing dependencies |
preinstall | runs before installing dependencies |
bun create
will automatically remove the "bun-create"
section from package.json
before writing it to the destination folder.
Reference
CLI flags
Flag | Description |
---|---|
--force | Overwrite existing files |
--no-install | Skip installing node_modules & tasks |
--no-git | Don’t initialize a git repository |
--open | Start & open in-browser after finish |
Environment variables
Name | Description |
---|---|
GITHUB_API_DOMAIN | If you’re using a GitHub enterprise or a proxy, you can customize the GitHub domain Bun pings for downloads |
GITHUB_TOKEN (or GITHUB_ACCESS_TOKEN ) | This lets bun create work with private repositories or if you get rate-limited. GITHUB_TOKEN is chosen over GITHUB_ACCESS_TOKEN if both exist. |
How bun create
works
How bun create
works
When you run
bun create ${template} ${destination}
, here’s what happens:IF remote template- GET
registry.npmjs.org/@bun-examples/${template}/latest
and parse it - GET
registry.npmjs.org/@bun-examples/${template}/-/${template}-${latestVersion}.tgz
- Decompress & extract
${template}-${latestVersion}.tgz
into${destination}
- If there are files that would overwrite, warn and exit unless
--force
is passed
- If there are files that would overwrite, warn and exit unless
- Download the tarball from GitHub’s API
- Decompress & extract into
${destination}
- If there are files that would overwrite, warn and exit unless
--force
is passed
- If there are files that would overwrite, warn and exit unless
- Open local template folder
- Delete destination directory recursively
-
Copy files recursively using the fastest system calls available (on macOS
fcopyfile
and Linux,copy_file_range
). Do not copy or traverse intonode_modules
folder if exists (this alone makes it faster thancp
) -
Parse the
package.json
(again!), updatename
to be${basename(destination)}
, remove thebun-create
section from thepackage.json
and save the updatedpackage.json
to disk.- IF Next.js is detected, add
bun-framework-next
to the list of dependencies - IF Create React App is detected, add the entry point in
/src/index.{js,jsx,ts,tsx}
topublic/index.html
- IF Relay is detected, add
bun-macro-relay
so that Relay works
- IF Next.js is detected, add
-
Auto-detect the npm client, preferring
pnpm
,yarn
(v1), and lastlynpm
-
Run any tasks defined in
"bun-create": { "preinstall" }
with the npm client -
Run
${npmClient} install
unless--no-install
is passed OR no dependencies are in package.json -
Run any tasks defined in
"bun-create": { "postinstall" }
with the npm client -
Run
git init; git add -A .; git commit -am "Initial Commit";
- Rename
gitignore
to.gitignore
. NPM automatically removes.gitignore
files from appearing in packages. - If there are dependencies, this runs in a separate thread concurrently while node_modules are being installed
- Using libgit2 if available was tested and performed 3x slower in microbenchmarks
- Rename