# Bun
Bun is a new:
- JavaScript/TypeScript/JSX transpiler
- JavaScript & CSS bundler
- Development server with 60fps Hot Module Reloading (& WIP support for React Fast Refresh)
- JavaScript Runtime Environment (powered by JavaScriptCore, what WebKit/Safari uses)
All in one fast & easy-to-use tool. Instead of 1,000 node_modules for development, you only need Bun.
**Bun is experimental software**. Join [Bun's Discord](https://bun.sh/discord) for help and have a look at [things that don't work yet](#things-that-dont-work-yet).
## Install:
```
# Global install is recommended so bun appears in your $PATH
npm install -g bun-cli
```
## Benchmarks
**CSS**: [Bun is 14x faster](./bench/hot-module-reloading/css-stress-test) than Next.js at hot reloading CSS. TODO: compare Vite
**JavaScript**: TODO
### Getting started
## Using Bun with Next.js
In your project folder root (where `package.json` is):
```bash
npm install -D bun-framework-next
bun bun --use next
bun
```
Many of Next.js' features are supported, but not all.
Here's what doesn't work yet:
- `getStaticPaths`
- same-origin `fetch` inside of `getStaticProps` or `getServerSideProps`
- locales, zones, `assetPrefix` (workaround: change `--origin \"http://localhsot:3000/assetPrefixInhere\"`)
- `next/image` is polyfilled to a regular `
` tag.
- `proxy` and anything else in `next.config.js`
- API, catch-all & catch-all fallback routes. Dynamic routes _are_ supported.
When using Next.js, Bun automatically reads configuration from `.env.local`, `.env.development` and `.env` (in that order). `process.env.NEXT_PUBLIC_` and `process.env.NEXT_` automatically are replaced via `--define`.
Currently, any time you import new dependencies from `node_modules`, you will need to re-run `bun bun --use next`. This will eventually be automatic.
## Using Bun with single page apps
In your project folder root (where `package.json` is):
```bash
bun bun ./entry-point-1.js ./entry-point-2.jsx
bun
```
By default, `bun` will look for any HTML files in the `public` directory and serve that. For browsers navigating to the page, the `.html` file extension is optional in the URL, and `index.html` will automatically rewrite for the directory.
Here are examples of routing from `public/` and how they're matched:
| Dev Server URL | File Path |
|----------------|-----------|
| /dir | public/dir/index.html |
| / | public/index.html |
| /index | public/index.html |
| /hi | public/hi.html |
| /file | public/file.html |
| /font/Inter.woff2 | public/font/Inter.woff2 |
| /hello | public/index.html |
If `public/index.html` exists, it becomes the default page instead of a 404 page, unless that pathname has a file extension.
#### Using Bun with Create React App
To use Bun with `create-react-app`, there are two changes you will need to make in `public/index.html`:
1. Replace `%PUBLIC_URL%` with `/`
2. Insert `