Co-authored-by: Michael H <git@riskymh.dev> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Marko Vejnovic <marko@bun.com>
2.3 KiB
Scaffold an empty Bun project with the interactive bun init command.
$ bun init
? Select a project template - Press return to submit.
❯ Blank
React
Library
✓ Select a project template: Blank
+ .gitignore
+ index.ts
+ tsconfig.json (for editor autocomplete)
+ README.md
To get started, run:
bun run index.ts
bun install v$BUN_LATEST_VERSION
+ @types/bun@$BUN_LATEST_VERSION
+ typescript@5.9.2
7 packages installed
Press enter to accept the default answer for each prompt, or pass the -y flag to auto-accept the defaults.
{% details summary="How bun init works" %}
bun init is a quick way to start a blank project with Bun. It guesses with sane defaults and is non-destructive when run multiple times.
It creates:
- a
package.jsonfile with a name that defaults to the current directory name - a
tsconfig.jsonfile or ajsconfig.jsonfile, depending if the entry point is a TypeScript file or not - an entry point which defaults to
index.tsunless any ofindex.{tsx, jsx, js, mts, mjs}exist or thepackage.jsonspecifies amoduleormainfield - a
README.mdfile
AI Agent rules (disable with $BUN_AGENT_RULE_DISABLED=1):
- a
CLAUDE.mdfile when Claude CLI is detected (disable withCLAUDE_CODE_AGENT_RULE_DISABLEDenv var) - a
.cursor/rules/*.mdcfile to guide Cursor AI to use Bun instead of Node.js and npm when Cursor is detected
If you pass -y or --yes, it will assume you want to continue without asking questions.
At the end, it runs bun install to install @types/bun.
{% /details %}
{% bunCLIUsage command="init" /%}
React
The --react flag will scaffold a React project:
$ bun init --react
The --react flag accepts the following values:
tailwind- Scaffold a React project with Tailwind CSSshadcn- Scaffold a React project with Shadcn/UI and Tailwind CSS
React + TailwindCSS
This will create a React project with Tailwind CSS configured with Bun's bundler and dev server.
$ bun init --react=tailwind
React + @shadcn/ui
This will create a React project with shadcn/ui and Tailwind CSS configured with Bun's bundler and dev server.
$ bun init --react=shadcn
