doc: Update bun.md #671
This commit is contained in:
parent
deeed5ec0b
commit
aadb7e664b
@ -135,6 +135,7 @@ Quick Reference
|
|||||||
[Yarn](./docs/yarn.md)<!--rehype:style=background: rgb(33 136 182);-->
|
[Yarn](./docs/yarn.md)<!--rehype:style=background: rgb(33 136 182);-->
|
||||||
[nvm](./docs/nvm.md)<!--rehype:style=background: rgb(132 132 132);-->
|
[nvm](./docs/nvm.md)<!--rehype:style=background: rgb(132 132 132);-->
|
||||||
[pnpm](./docs/pnpm.md)<!--rehype:style=background: rgb(191 133 0);-->
|
[pnpm](./docs/pnpm.md)<!--rehype:style=background: rgb(191 133 0);-->
|
||||||
|
[Bun](./docs/bun.md)<!--rehype:style=background: rgb(157 49 81);-->
|
||||||
<!--rehype:class=home-card-->
|
<!--rehype:class=home-card-->
|
||||||
|
|
||||||
## 工具
|
## 工具
|
||||||
|
13
assets/bun.svg
Normal file
13
assets/bun.svg
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 70" height="1em" width="1em">
|
||||||
|
<path d="M71.09 20.74c-.16-.17-.33-.34-.5-.5s-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5A26.46 26.46 0 0 1 75.5 35.7c0 16.57-16.82 30.05-37.5 30.05-11.58 0-21.94-4.23-28.83-10.86l.5.5.5.5.5.5.5.5.5.5.5.5.5.5C19.55 65.3 30.14 69.75 42 69.75c20.68 0 37.5-13.48 37.5-30 0-7.06-3.04-13.75-8.41-19.01Z"/>
|
||||||
|
<path d="M73 35.7c0 15.21-15.67 27.54-35 27.54S3 50.91 3 35.7C3 26.27 9 17.94 18.22 13S33.18 3 38 3s8.94 4.13 19.78 10C67 17.94 73 26.27 73 35.7Z" style="fill:#fbf0df"/>
|
||||||
|
<path data-name="Bottom Shadow" d="M73 35.7a21.67 21.67 0 0 0-.8-5.78c-2.73 33.3-43.35 34.9-59.32 24.94A40 40 0 0 0 38 63.24c19.3 0 35-12.35 35-27.54Z" style="fill:#f6dece"/>
|
||||||
|
<path data-name="Light Shine" d="M24.53 11.17C29 8.49 34.94 3.46 40.78 3.45A9.29 9.29 0 0 0 38 3c-2.42 0-5 1.25-8.25 3.13-1.13.66-2.3 1.39-3.54 2.15-2.33 1.44-5 3.07-8 4.7C8.69 18.13 3 26.62 3 35.7v1.19c6.06-21.41 17.07-23.04 21.53-25.72Z" style="fill:#fffefc"/>
|
||||||
|
<path d="M35.12 5.53A16.41 16.41 0 0 1 29.49 18c-.28.25-.06.73.3.59 3.37-1.31 7.92-5.23 6-13.14-.08-.45-.67-.33-.67.08Zm2.27 0A16.24 16.24 0 0 1 39 19c-.12.35.31.65.55.36 2.19-2.8 4.1-8.36-1.62-14.36-.29-.26-.74.14-.54.49Zm2.76-.17A16.42 16.42 0 0 1 47 17.12a.33.33 0 0 0 .65.11c.92-3.49.4-9.44-7.17-12.53-.4-.16-.66.38-.33.62Zm-18.46 10.4a16.94 16.94 0 0 0 10.47-9c.18-.36.75-.22.66.18-1.73 8-7.52 9.67-11.12 9.45-.38.01-.37-.52-.01-.63Z" style="fill:#ccbea7;fill-rule:evenodd"/>
|
||||||
|
<path d="M38 65.75C17.32 65.75.5 52.27.5 35.7c0-10 6.18-19.33 16.53-24.92 3-1.6 5.57-3.21 7.86-4.62 1.26-.78 2.45-1.51 3.6-2.19C32 1.89 35 .5 38 .5s5.62 1.2 8.9 3.14c1 .57 2 1.19 3.07 1.87 2.49 1.54 5.3 3.28 9 5.27C69.32 16.37 75.5 25.69 75.5 35.7c0 16.57-16.82 30.05-37.5 30.05ZM38 3c-2.42 0-5 1.25-8.25 3.13-1.13.66-2.3 1.39-3.54 2.15-2.33 1.44-5 3.07-8 4.7C8.69 18.13 3 26.62 3 35.7c0 15.19 15.7 27.55 35 27.55S73 50.89 73 35.7c0-9.08-5.69-17.57-15.22-22.7-3.78-2-6.73-3.88-9.12-5.36-1.09-.67-2.09-1.29-3-1.84C42.63 4 40.42 3 38 3Z"/><g>
|
||||||
|
<path d="M45.05 43a8.93 8.93 0 0 1-2.92 4.71 6.81 6.81 0 0 1-4 1.88A6.84 6.84 0 0 1 34 47.71 8.93 8.93 0 0 1 31.12 43a.72.72 0 0 1 .8-.81h12.34a.72.72 0 0 1 .79.81Z" style="fill:#b71422" data-name="Background"/>
|
||||||
|
<path data-name="Background" d="M34 47.79a6.91 6.91 0 0 0 4.12 1.9 6.91 6.91 0 0 0 4.11-1.9 10.63 10.63 0 0 0 1-1.07 6.83 6.83 0 0 0-4.9-2.31 6.15 6.15 0 0 0-5 2.78c.23.21.43.41.67.6Z" style="fill:#ff6164"/>
|
||||||
|
<path data-name="Outline" d="M34.16 47a5.36 5.36 0 0 1 4.19-2.08 6 6 0 0 1 4 1.69c.23-.25.45-.51.66-.77a7 7 0 0 0-4.71-1.93 6.36 6.36 0 0 0-4.89 2.36 9.53 9.53 0 0 0 .75.73Z"/>
|
||||||
|
<path data-name="Outline" d="M38.09 50.19a7.42 7.42 0 0 1-4.45-2 9.52 9.52 0 0 1-3.11-5.05 1.2 1.2 0 0 1 .26-1 1.41 1.41 0 0 1 1.13-.51h12.34a1.44 1.44 0 0 1 1.13.51 1.19 1.19 0 0 1 .25 1 9.52 9.52 0 0 1-3.11 5.05 7.42 7.42 0 0 1-4.44 2Zm-6.17-7.4c-.16 0-.2.07-.21.09a8.29 8.29 0 0 0 2.73 4.37A6.23 6.23 0 0 0 38.09 49a6.28 6.28 0 0 0 3.65-1.73 8.3 8.3 0 0 0 2.72-4.37.21.21 0 0 0-.2-.09Z"/></g><g><ellipse data-name="Right Blush" cx="53.22" cy="40.18" rx="5.85" ry="3.44" style="fill:#febbd0"/><ellipse data-name="Left Bluch" cx="22.95" cy="40.18" rx="5.85" ry="3.44" style="fill:#febbd0"/>
|
||||||
|
<path d="M25.7 38.8a5.51 5.51 0 1 0-5.5-5.51 5.51 5.51 0 0 0 5.5 5.51Zm24.77 0A5.51 5.51 0 1 0 45 33.29a5.5 5.5 0 0 0 5.47 5.51Z" style="fill-rule:evenodd"/>
|
||||||
|
<path d="M24 33.64a2.07 2.07 0 1 0-2.06-2.07A2.07 2.07 0 0 0 24 33.64Zm24.77 0a2.07 2.07 0 1 0-2.06-2.07 2.07 2.07 0 0 0 2.04 2.07Z" style="fill:#fff;fill-rule:evenodd"/></g></svg>
|
After Width: | Height: | Size: 3.5 KiB |
146
docs/bun.md
146
docs/bun.md
@ -13,16 +13,20 @@ curl -fsSL https://bun.sh/install | bash
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Bun 与 npm/Yarn 命令比较
|
### Bun 与 npm/Yarn 命令比较
|
||||||
|
<!--rehype:wrap-class=col-span-2 row-span-3-->
|
||||||
|
|
||||||
npm/Yarn | Bun | 说明
|
npm | Yarn | Bun | 说明
|
||||||
:- | :- | :-
|
:- | :- | :- | :-
|
||||||
`npm install`, `yarn add` | `bun add` | 安装依赖
|
`npm install` | `yarn add` | `bun add` | 安装依赖
|
||||||
`npm init`, `yarn init` | `bun init` | 创建 `package.json` 文件
|
`npm init` | `yarn init` | `bun init` | 创建 `package.json` 文件
|
||||||
`npm install -g`, `yarn global add` | `bun global add` | 全局安装包
|
`npm install -g` | `yarn global add` | `bun global add` | 全局安装包
|
||||||
`npm run`, `yarn run` | `bun run` | 运行脚本
|
`npm run` | `yarn run` | `bun run` | 运行脚本
|
||||||
`npm uninstall`, `yarn remove` | `bun remove` | 移除包
|
`npm uninstall` | `yarn remove` | `bun remove` | 移除包
|
||||||
`npm update`, `yarn upgrade` | `bun upgrade` | 更新包
|
`npm update` | `yarn upgrade` | `bun upgrade` | 更新包
|
||||||
`npm cache clean`, `yarn cache clean` | `bun cache clean` | 清理缓存目录
|
`npm cache clean` | `yarn cache clean` | `bun cache clean` | 清理缓存目录
|
||||||
|
<!--rehype:className=left-align-->
|
||||||
|
|
||||||
|
参考备忘清单: [npm](./npm.md)、[yarn](./yaml.md)、[pnpm](./pnpm.md)
|
||||||
|
|
||||||
### 创建项目
|
### 创建项目
|
||||||
|
|
||||||
@ -36,7 +40,14 @@ bun create <template> <project-name>
|
|||||||
bun create react my-react-app
|
bun create react my-react-app
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 查看已安装包
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun ls
|
||||||
|
```
|
||||||
|
|
||||||
### 安装依赖
|
### 安装依赖
|
||||||
|
<!--rehype:wrap-class=row-span-2-->
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun add <package>
|
bun add <package>
|
||||||
@ -45,31 +56,14 @@ bun add <package>
|
|||||||
选项:
|
选项:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
--dev, -D # 安装到 devDependencies
|
--dev, -D # 安装到 devDependencies
|
||||||
--global, -g # 全局安装包
|
--global, -g # 全局安装包
|
||||||
--exact, -E # 将包安装为精确版本
|
--exact, -E # 将包安装为精确版本
|
||||||
--tilde, -T # 安装有相同次要版本的包的最新版本
|
--tilde, -T # 安装有相同次要版本的包的最新版本
|
||||||
```
|
|
||||||
|
|
||||||
### 移除依赖
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bun remove <package>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 更新依赖
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bun upgrade
|
|
||||||
```
|
|
||||||
|
|
||||||
选项:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
--latest # 更新到最新版本
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 运行脚本
|
### 运行脚本
|
||||||
|
<!--rehype:wrap-class=row-span-3-->
|
||||||
|
|
||||||
在 `package.json` 中定义脚本:
|
在 `package.json` 中定义脚本:
|
||||||
|
|
||||||
@ -92,10 +86,22 @@ bun run <script>
|
|||||||
bun run start
|
bun run start
|
||||||
```
|
```
|
||||||
|
|
||||||
### 查看已安装包
|
### 移除依赖
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun ls
|
bun remove <package>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 更新依赖
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
选项:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
--latest # 更新到最新版本
|
||||||
```
|
```
|
||||||
|
|
||||||
### 清理缓存
|
### 清理缓存
|
||||||
@ -125,10 +131,86 @@ bun test # 运行测试
|
|||||||
bun completions # 生成 shell 补全脚本
|
bun completions # 生成 shell 补全脚本
|
||||||
```
|
```
|
||||||
|
|
||||||
|
包管理器
|
||||||
|
---
|
||||||
|
|
||||||
|
### bin 目录的路径
|
||||||
|
|
||||||
|
要打印本地项目的 `bin` 目录的路径
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm bin
|
||||||
|
# /path/to/current/pro/node_modules/.bin
|
||||||
|
```
|
||||||
|
|
||||||
|
全局 bin 目录
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm bin -g
|
||||||
|
# <$HOME>/.bun/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
### 打印依赖项
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm ls --all
|
||||||
|
# /path/to/project node_modules (135)
|
||||||
|
# ├── @eslint-community/eslint-utils@4.4.0
|
||||||
|
# ├── @eslint-community/regexpp@4.5.0
|
||||||
|
# ├── @eslint/eslintrc@2.0.2
|
||||||
|
# ├── @eslint/js@8.38.0
|
||||||
|
# ├── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
打印所有已安装的依赖项,包括 `n` 阶依赖项。
|
||||||
|
|
||||||
|
### 打印已安装及已解决依赖项
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm ls
|
||||||
|
# /path/to/project node_modules (135)
|
||||||
|
# ├── eslint@8.38.0
|
||||||
|
# ├── react@18.2.0
|
||||||
|
# ├── react-dom@18.2.0
|
||||||
|
# ├── typescript@5.0.4
|
||||||
|
# └── zod@3.21.4
|
||||||
|
```
|
||||||
|
|
||||||
|
打印当前项目中已安装依赖项及其已解决版本的列表,不包括其依赖项
|
||||||
|
|
||||||
|
### 全局模块缓存的路径
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm cache
|
||||||
|
```
|
||||||
|
|
||||||
|
要打印 Bun 的全局模块缓存的路径
|
||||||
|
|
||||||
|
### 清除全局模块缓存
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm cache rm
|
||||||
|
```
|
||||||
|
|
||||||
|
### 列出全局安装
|
||||||
|
|
||||||
|
列出所有全局安装的软件包:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm ls -g
|
||||||
|
```
|
||||||
|
|
||||||
|
列出所有全局安装的软件包,包括 n 阶依赖项:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun pm ls -g --all
|
||||||
|
```
|
||||||
|
|
||||||
示例
|
示例
|
||||||
---
|
---
|
||||||
|
|
||||||
### 安装包
|
### 安装包
|
||||||
|
<!--rehype:wrap-class=row-span-2-->
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 将包添加到 dependencies
|
# 将包添加到 dependencies
|
||||||
|
Loading…
x
Reference in New Issue
Block a user