new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Bun · Package manager · all subjects

add: dependency types

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

bun add --peer flag for peer dependencies

Use the --peer flag with bun add to add an npm package as a peer dependency. This adds the package to peerDependencies in package.json. Example: bun add @types/bun --peer

--dev flag for dev dependencies

Use `--dev`, `--development`, `-d`, or `-D` to add a package as a dev dependency (written to `devDependencies`). Example: `bun add --dev @types/react` or `bun add -d @types/react`.

--optional flag for optional dependencies

Use `--optional` to add a package as an optional dependency (written to `optionalDependencies`). Example: `bun add --optional lodash`.

--peer flag for peer dependencies

Use `--peer` to add a package as a peer dependency (written to `peerDependencies`). Example: `bun add --peer @types/bun`. Bun installs peer dependencies by default, so no additional `devDependencies` entry is needed.

Adding devDependencies with bun add

Use bun i -d <package> to add a devDependency. For example: bun i -d @types/bun.

bun add --development flag

Use `bun add --development` to add an npm package as a development dependency. This adds the package to `devDependencies` in `package.json`.

bun add --dev shorthand

The `--dev` flag is a shorthand for `--development` when adding packages as development dependencies.

bun add -d shorthand

The `-d` flag is a shorthand for `--development` when adding packages as development dependencies.

Development dependency example

The command `bun add zod --dev` adds the zod package as a development dependency to `devDependencies` in `package.json` with version `^4.0.0`.

bun add --optional flag for optional dependencies

To add an npm package as an optional dependency, use the --optional flag with bun add. For example, running 'bun add zod --optional' adds the package to optionalDependencies in package.json.

Optional dependencies stored in optionalDependencies field

Packages added with the --optional flag are stored in the optionalDependencies field of package.json.

bun add adds to dependencies

The bun add command adds packages to the 'dependencies' section of package.json by default.

Give your agent this brain