bun create - BunDocumentation Index Search...⌘KInstall Bun Search...Navigation Get Started bun createRuntimePackage ManagerBundlerTest RunnerGuidesReferenceBlogFeedback:first-child]:!hidden peer-[.is-custom]:[&>:first-child]:sm:!hidden peer-[.is-custom]:[&>:first-child]:md:!hidden peer-[.is-custom]:[&>:first-child]:lg:!hidden peer-[.is-custom]:[&>:first-child]:xl:!hidden">Get StartedWelcome to BunInstallationQuickstartTypeScriptTypeScript 6 and 7bun initbun createCore RuntimeBun RuntimeWatch ModeDebuggingREPLbunfig.tomlFile & Module SystemFile TypesModule ResolutionJSXAuto-installPluginsFile System RouterHTTP serverServerRoutingCookiesTLSError HandlingMetricsNetworkingFetchWebSocketsTCPUDPDNSData & StorageCookiesFile I/OStreamsBinary DataArchiveSQLSQLiteS3RedisConcurrencyWorkersProcess & SystemEnvironment VariablesShellSpawnWebViewCronInterop & ToolingNode-APIFFIC CompilerTranspilerUtilitiesCSRF ProtectionSecretsConsoleTOMLYAMLMarkdownJSON5JSONLHTMLRewriterImageHashingGlobSemverColorUtilsStandards & CompatibilityGlobalsBun APIsWeb APIsNode.js CompatibilityContributingRoadmapBenchmarkingContributingBuilding WindowsBindgenLicense On this pageFrom a React componentHow this worksUsing TailwindCSS with BunUsing shadcn/ui with BunFrom npmFrom GitHubFrom a local templateSetup logicReferenceCLI flagsEnvironment variablesGet Startedbun create Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_n4ctdbsnlht5lebsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed"> *]:[overflow-wrap:anywhere]"> Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_1cctdbsnlht5lebsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed"> bun create is optional — Bun works without any configuration. This command exists to make getting started faster.
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- 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 provides everything developers loved about Create React App, but with modern tooling, faster builds, and backend support.
How this works
When you run bun create , 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 run bun create , 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 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.
Bun’s templater can be extended to support custom templates defined on your local file system. These templates should live in one of the following directories:
$HOME/.bun-create/: global templates
/.bun-create/: project-specific templates
You can customize the global template path by setting the BUN_CREATE_DIR environment variable.
To create a local template, navigate to $HOME/.bun-create and create a new directory with the desired name of your template.
Yes NoSuggest editsRaise issuebun initPreviousBun RuntimeNext⌘I xgithubdiscordyoutubePowered byThis documentation is built and hosted on Mintlify, a developer documentation platform
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main contentBun home pageCreate a new Bun project from a React component, a create- npm package, a GitHub repo, or a local template
bun create ./MyComponent.jsx # .tsx also supported
{
"dependencies": {
"tailwindcss": "^4",
"bun-plugin-tailwind": "latest"
}
}
We also configure bunfig.toml to use Bun’s TailwindCSS plugin with Bun.serve()
bunfig.toml[serve.static] plugins = ["bun-plugin-tailwind"]And a ${component}.css file with @import "tailwindcss"; at the top: MyComponent.css
@import "tailwindcss";Using shadcn/ui with Bun shadcn/ui is an extremely popular component library tool for building web applications. bun create scans for any shadcn/ui components imported from @/components/ui. If it finds any, it runs: terminal
# Assuming bun detected imports to @/components/ui/accordion and @/components/ui/button bunx shadcn@canary add accordion button # and any other componentsSince 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 a src/ directory) components.json so that shadcn/ui knows its a shadcn/ui project styles/globals.css file that configures Tailwind v4 in the way that shadcn/ui expects ${component}.build.ts file that builds the component for production with bun-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
bun create template> []Assuming you don’t have a local template with the same name, this command will download and execute the create- package from npm. The following two commands will behave identically: terminal
bun create remix bunx create-remixRefer to the documentation of the associated create- package for complete documentation and usage instructions. From GitHub This will download the contents of the GitHub repo to disk. terminal
bun create user>/repo> bun create github.com/user>/repo>Optionally specify a name for the destination folder. If no destination is specified, the repo name will be used. terminal
bun create user>/repo> mydir bun create github.com/user>/repo> mydirBun will perform the following steps: 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.
cd $HOME/.bun-create mkdir foo cd fooThen, create a package.json file in that directory with the following contents: package.json
{
"name": "foo"
}
You can run 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{
"name": "@bun-examples/simplereact",
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"bun-create": {
"preinstall": "echo 'Installing...'", // a single command
"postinstall": ["echo 'Done!'"], // an array of commands
"start": "bun run echo 'Hello world!'"
}
}
The following fields are supported. Each of these can correspond to a string or array of strings. An array of commands will be executed in order.
FieldDescriptionpostinstallruns after installing dependenciespreinstallruns before installing dependencies
After cloning a template, bun create will automatically remove the "bun-create" section from package.json before writing it to the destination folder.
Reference
CLI flags
FlagDescription--forceOverwrite existing files--no-installSkip installing node_modules & tasks--no-gitDon’t initialize a git repository--openStart & open in-browser after finish
Environment variables
NameDescriptionGITHUB_API_DOMAINIf you’re using a GitHub enterprise or a proxy, you can customize the GitHub domain Bun pings for downloadsGITHUB_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
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 GitHub repo 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 ELSE IF local template 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 into node_modules folder if exists (this alone makes it faster than cp) Parse the package.json (again!), update name to be ${basename(destination)}, remove the bun-create section from the package.json and save the updated package.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} to public/index.html IF Relay is detected, add bun-macro-relay so that Relay works Auto-detect the npm client, preferring pnpm, yarn (v1), and lastly npm 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 microbenchmarksWas this page helpful?
bun create - Bun,AI智能索引,全网链接索引,智能导航,网页索引
- Create a new Bun project from a React component, a create- npm package, a GitHub repo, or a local template