Create a react app with bun

ashirbadgudu

Ashirbad Panigrahi

Posted on July 16, 2022

Create a react app with bun

Want to use bun for your next react projects?


Install bun

First run the following command to check bun is installed or not

bun -v
Enter fullscreen mode Exit fullscreen mode

If you don't have bun installed then run the following command to install bun

curl https://bun.sh/install | bash
Enter fullscreen mode Exit fullscreen mode

Create a react app

Now run the following command to create a react app

bun create react [your-app-name]
Enter fullscreen mode Exit fullscreen mode

It will create a new directory with the name of your app. To start the app run the following command

cd your-app-name
bun dev
Enter fullscreen mode Exit fullscreen mode

Build production bundle for react app

By default bun does not ship with react-scripts so you need to install it first.

bun a react-scripts -d
Enter fullscreen mode Exit fullscreen mode

Here we install it as a dev dependency.

Then run the following command to build the production bundle

bun react-scripts build
Enter fullscreen mode Exit fullscreen mode

When you run the command above it will build the production bundle and it will be stored in the build directory.

Adding scripts to your package.json

We can add the following scripts to our package.json file

{
  "scripts": {
    "start": "bun dev",
    "build": "react-scripts build"
  }
}
Enter fullscreen mode Exit fullscreen mode

Now we can run the following command to start the app

bun start
Enter fullscreen mode Exit fullscreen mode

And we can run the following command to build the production bundle

bun run build
Enter fullscreen mode Exit fullscreen mode

Bonus:

By default bun creates react app with javascript but we can easily use typescript by changing the file extension from .jsx to .tsx

Get Full Source Code In GitHub

💖 💪 🙅 🚩
ashirbadgudu
Ashirbad Panigrahi

Posted on July 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Create a react app with bun
react Create a react app with bun

July 16, 2022