这是一份 Bun
软件包管理器备忘单,其中列出了 Bun
常用命令使用清单
curl -fsSL https://bun.sh/install | bash
npm/Yarn | Bun | 说明 |
---|---|---|
npm install , yarn add | bun add | 安装依赖 |
npm init , yarn init | bun init | 创建 package.json 文件 |
npm install -g , yarn global add | bun global add | 全局安装包 |
npm run , yarn run | bun run | 运行脚本 |
npm uninstall , yarn remove | bun remove | 移除包 |
npm update , yarn upgrade | bun upgrade | 更新包 |
npm cache clean , yarn cache clean | bun cache clean | 清理缓存目录 |
bun create <template> <project-name>
示例:
bun create react my-react-app
bun add <package>
选项:
--dev, -D # 安装到 devDependencies
--global, -g # 全局安装包
--exact, -E # 将包安装为精确版本
--tilde, -T # 安装有相同次要版本的包的最新版本
bun remove <package>
bun upgrade
选项:
--latest # 更新到最新版本
在 package.json
中定义脚本:
"scripts": {
"start": "node index.js",
"test": "jest"
}
运行脚本:
bun run <script>
例如:
bun run start
bun ls
bun cache clean
bun global add <package>
bun global remove <package>
bun bunfile # 管理 Bunfile
bun dev # 运行开发服务器
bun test # 运行测试
bun completions # 生成 shell 补全脚本
# 将包添加到 dependencies
$ bun add <package>
# 将包添加到 devDependencies
$ bun add -D <package>
# 将包安装为精确版本
$ bun add -E <package>
# 全局安装包
$ bun global add <package>
$ bun remove <package>
从所有类型的依赖项中删除包
# 列出已安装的软件包
$ bun ls
$ bun cache clean
清理缓存目录
$ bun run <script>
在 package.json
中定义的脚本将被执行