Files
bun.sh/docs/guides/ecosystem/vite.md
Clément P 5f09a4dd0a Update vite.md (#6399)
remove outdated information
2023-10-10 15:36:28 -07:00

1.4 KiB
Raw Blame History

name
name
Build a frontend using Vite and Bun

{% callout %} While Vite currently works with Bun, it has not been heavily optimized, nor has Vite been adapted to use Bun's bundler, module resolver, or transpiler. {% /callout %}


Vite works out of the box with Bun. Get started with one of Vite's templates.

$ bun create vite my-app
✔ Select a framework:  React
✔ Select a variant:  TypeScript + SWC
Scaffolding project in /path/to/my-app...

Then cd into the project directory and install dependencies.

cd my-app
bun install

Start the development server with the vite CLI using bunx.

The --bun flag tells Bun to run Vite's CLI using bun instead of node; by default Bun respects Vite's #!/usr/bin/env node shebang line.

bunx --bun vite

To simplify this command, update the "dev" script in package.json to the following.

  "scripts": {
-   "dev": "vite",
+   "dev": "bunx --bun vite",
    "build": "vite build",
    "serve": "vite preview"
  },
  // ...

Now you can start the development server with bun run dev.

bun run dev

The following command will build your app for production.

$ bunx --bun vite build

This is a stripped down guide to get you started with Vite + Bun. For more information, see the Vite documentation.