Introduction:
Recently, I came across an exciting JavaScript tool that got me pumped up – Bun. It's a powerful "all-in-one toolkit for JavaScript and TypeScript apps" that can be considered a worthy alternative to NPM and Yarn, but with one notable difference – it's incredibly fast.
In this blog post, we'll explore how you can leverage Bun as a replacement for NPM and Yarn in your local development environment and discover how it can supercharge your typical Laravel application.
Installing Bun
Getting Bun up and running is a breeze. Depending on your system, you can choose from the following installation methods:
For Mac, Linux, or WSL Users:
curl -fsSL https://bun.sh/install | bash
Homebrew Users:
If you prefer to use Homebrew:
brew tap oven-sh/bun
brew install bun
Please note that Windows users can access an experimental native build of Bun, which comes with limited features for now, but it's a promising start. Features like adding, removing, and installing packages are not fully functional on Windows yet.
Once Bun is successfully installed, you can confirm it by running the following command in your Terminal:
bun --version
Utilizing Bun
Now that Bun is at your disposal, let's see how you can replace NPM and Yarn in your workflow. To demonstrate, we'll work with a fresh Laravel Jetstream application featuring Inertia and Vue.
To install all dependencies from an existing package.json file, simply execute the following command:
bun install
Installing Dependencies with Bun
Adding dependencies with Bun is just as straightforward as you're used to with Yarn or NPM. To install a new dependency, use:
bun add [PACKAGE_NAME]
If you want it as a dev-dependency instead:
bun add -d [PACKAGE_NAME]
And just like the install command, adding new dependencies is remarkably fast.
Removing Dependencies
Need to clean house and remove some dependencies? Bun has you covered there too. Use the rm or remove command:
bun rm [PACKAGE_NAME]
And there you have it! With Bun in your toolkit, you can replace NPM and Yarn, experiencing up to 33x faster performance. Happy coding!
Top comments (0)