In addition to its runtime, Bun comes with a package manager that is relatively faster than the alternatives. This can be attributed to the fact that after a module is installed, Bun downloads it into a global module cache. If the module is needed again later, Bun checks the cache first to avoid redundant installations.
Below are some commonly used Bun commands:
- To install all the dependencies:
bun install
- To add a new package to the project:
bun add <package>
- To add a new development-only package:
bun add <package> --dev
- To remove a package from the project:
bun remove <package>
- To update a specific package to its latest version:
bun update <package>
- To execute a specified script:
bun run <script>
Bun is not only a runtime but also a bundler designed to bundle JavaScript and TypeScript. It includes a minifier that can target code for the browser, Node.js, and other platforms. This sets Bun apart from other runtimes, which rely on third-party tools such as WebPack, Rollup, and Parcel for bundling.
To bundle the index.tx
file, use the following command:
bun build ./index.tsx --outdir ./build
This command writes the bundle to the ./build
directory on the disk.