Bun 包管理工具配置

预计阅读时间: 小于 1 分钟

工具安装 Windows

安装命令
1powershell -c "irm bun.sh/install.ps1 | iex"

工具安装 macOS

安装命令
1curl -fsSL https://bun.sh/install | bash

:可以使用 npm 命令进行全局安装。

工具安装 Linux

安装命令
1curl -fsSL https://bun.sh/install | bash

:使用 yarn install 命令安装依赖时报错。

配置镜像源

  • 创建名为 bunfig.toml 的文件
  • 文件内容如下:
bunfig.toml 文件配置
1[package-locks]
2lockb = {
3  registry = "https://registry.npmmirror.com"
4}
  • 官方文档:Bun 「👈 点击访问」

操作命令

bun 相关命令
1Commands:
2  run       ./my-script.ts       Execute a file with Bun
3            lint                 Run a package.json script
4  test                           Run unit tests with Bun
5  x         next                 Execute a package binary (CLI), installing if needed (bunx)
6  repl                           Start a REPL session with Bun
7  exec                           Run a shell script directly with Bun
8
9  install                        Install dependencies for a package.json (bun i)
10  add       elysia               Add a dependency to package.json (bun a)
11  remove    zod                  Remove a dependency from package.json (bun rm)
12  update    underscore           Update outdated dependencies
13  link      [<package>]          Register or link a local npm package
14  unlink                         Unregister a local npm package
15  pm <subcommand>                Additional package management utilities
16
17  build     ./a.ts ./b.jsx       Bundle TypeScript & JavaScript into a single file
18
19  init                           Start an empty Bun project from a blank template
20  create    tailwindcss          Create a new project from a template (bun c)
21  upgrade                        Upgrade to latest version of Bun.
22  <command> --help               Print help text for command.
23
24Learn more about Bun:            https://bun.sh/docs
25Join our Discord community:      https://bun.sh/discord
注意「🔔」:
  • 配置文件 bunfig.toml 要放置项目的根目录下;
  • 配置文件 bunfig.toml 配置的镜像源地址使用的是阿里的淘宝镜像[可根据自己的实际需求做相应的调整];
  • 该文件只对当前项目有效,若要配置全局镜像源地址,需要修改 ~/.bun/config.toml 文件进行配置。