Sure, here's a more detailed guide on using bun
as a developer:
First, ensure you have bun
installed globally or within your project. You can install it via npm or yarn:
npm install -g @bun/cli
or
yarn global add @bun/cli
bun run <script>
: Run the start script or any script specified inpackage.json
.bun run start
: Specifically run thestart
script defined inpackage.json
.
bun install <package>
: Install a specific package.bun install
: Install all dependencies listed inpackage.json
.
- run: Executes a file with Bun. You can specify the script to run, e.g.,
bun run ./my-script.ts
. - lint: Runs a script defined in
package.json
for linting purposes.
- test: Runs unit tests with Bun.
- install: Installs dependencies for a
package.json
file. Equivalent tobun i
. - add: Adds a dependency to
package.json
. Syntax:bun add <package>
. - remove: Removes a dependency from
package.json
. Syntax:bun remove <package>
. - update: Updates outdated dependencies.
- link: Registers or links a local npm package.
- unlink: Unregisters a local npm package.
- pm: Additional package management utilities.
- build: Bundles TypeScript & JavaScript files into a single file. Syntax:
bun build ./a.ts ./b.jsx
.
- repl: Starts a REPL (Read-Eval-Print Loop) session with Bun.
- create: Creates a new project from a template. Syntax:
bun create <template>
.
- init: Starts an empty Bun project from a blank template.
- upgrade: Upgrades to the latest version of Bun.
-
<command> --help
: Prints help text for a specific command. -
bunx <package> '<command>'
: Execute a package directly, similar tonpx
.
bun build ./index.tsx
: Bundle a project for browsers.
bun test
: Run tests using Bun's built-in test runner.
bun create <template> [<destination>]
: Scaffold a new project using a template.bun run --filter <workspace> <script>
: Run multiple workspace scripts in parallel.
bun
provides several flags and options to customize its behavior:
--watch
: Automatically restart the process on file change.--hot
: Enable auto reload in the Bun runtime, test runner, or bundler.--smol
: Use less memory but run garbage collection more often.--inspect
,--inspect-wait
,--inspect-brk
: Activate Bun's debugger.--if-present
: Exit without an error if the entrypoint does not exist.--no-install
,--install
: Configure auto-install behavior.--prefer-offline
,--prefer-latest
: Control package resolution behavior.--conditions
: Pass custom conditions to resolve.--silent
: Don't print the script command.--env-file
: Load environment variables from specified file(s).--cwd
: Specify the absolute path to resolve files & entry points from.--config
: Specify the path to Bun config file.
- Bun Documentation: Explore more detailed documentation on Bun's features and usage.
- Bun Discord Community: Join the Bun Discord community for discussions and support.
This guide covers the basic usage of bun
for common development tasks. For more advanced usage or specific use cases, refer to the official Bun documentation and community resources.