← 返回命令列表

Linux command

bun-add 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Add a dependency

bun add [lodash]

Add a dev dependency

bun add -D [jest]

Add multiple packages

bun add [react] [react-dom]

Add with exact version

bun add --exact [typescript@5.0.0]

Add globally

bun add -g [typescript]

Add from git repository

bun add git+https://github.com/[user]/[repo]

Add as peer dependency

bun add -P [react]

Dry run without changes

bun add --dry-run [package]

说明

bun add adds packages to package.json and installs them into node_modules. It updates or creates bun.lockb for reproducible installs. The command is significantly faster than npm or yarn alternatives.

参数

-D, --dev
Add to devDependencies
-P, --peer
Add to peerDependencies
-O, --optional
Add to optionalDependencies
-E, --exact
Use exact version without ^ or ~ prefix
-g, --global
Install globally to Bun's global store
--production
Skip devDependencies
--registry _url_
Use custom npm registry
--lockfile-only
Update lockfile without installing
--dry-run
Simulate without making changes
--force
Force install despite warnings
--trust
Allow lifecycle scripts for added packages

FAQ

What is the bun-add command used for?

bun add adds packages to package.json and installs them into node_modules. It updates or creates bun.lockb for reproducible installs. The command is significantly faster than npm or yarn alternatives.

How do I run a basic bun-add example?

Run `bun add [lodash]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -D, --dev do in bun-add?

Add to devDependencies