doc: Update docs/pnpm.md #670 c0903a400c

This commit is contained in:
jaywcjlove
2024-06-24 19:32:04 +00:00
parent edf8151a62
commit 2582f5d1aa
5 changed files with 161 additions and 80 deletions

View File

@ -423,7 +423,8 @@
<table><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>/path/to/project/.npmrc</code></td><td align="left">每个项目的配置文件</td></tr><tr><td align="left"><code>~/.npmrc</code></td><td align="left">每个用户的配置文件</td></tr><tr><td align="left"><code>$PREFIX/etc/npmrc</code></td><td align="left">全局配置文件</td></tr><tr><td align="left"><code>/path/to/npm/npmrc</code></td><td align="left">npm 内置配置文件</td></tr></tbody></table>
<table class="left-align"><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>/path/to/project/.npmrc</code></td><td align="left">每个项目的配置文件</td></tr><tr><td align="left"><code>~/.npmrc</code></td><td align="left">每个用户的配置文件</td></tr><tr><td align="left"><code>$PREFIX/etc/npmrc</code></td><td align="left">全局配置文件</td></tr><tr><td align="left"><code>/path/to/npm/npmrc</code></td><td align="left">npm 内置配置文件</td></tr></tbody></table>
<!--rehype:className=left-align-->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="配置内容"><a aria-hidden="true" tabindex="-1" href="#配置内容"><span class="icon icon-link"></span></a>配置内容</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-ini code-highlight"><span class="code-line"><span class="token comment"># last modified: 01 Jan 2016</span>
</span><span class="code-line"><span class="token comment">; Set a new registry for a scoped package</span>
@ -465,7 +466,8 @@
<table><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>npm</code></td><td align="left"><a href="https://registry.npmjs.org/">https://registry.npmjs.org/</a></td></tr><tr><td align="left"><code>yarn</code></td><td align="left"><a href="https://registry.yarnpkg.com/">https://registry.yarnpkg.com/</a></td></tr><tr><td align="left"><code>tencent</code></td><td align="left"><a href="https://mirrors.cloud.tencent.com/npm/">https://mirrors.cloud.tencent.com/npm/</a></td></tr><tr><td align="left"><code>cnpm</code></td><td align="left"><a href="https://r.cnpmjs.org/">https://r.cnpmjs.org/</a></td></tr><tr><td align="left"><code>taobao</code></td><td align="left"><a href="https://registry.npmmirror.com/">https://registry.npmmirror.com/</a></td></tr><tr><td align="left"><code>npmMirror</code></td><td align="left"><a href="https://skimdb.npmjs.com/registry/">https://skimdb.npmjs.com/registry/</a></td></tr></tbody></table>
<table class="left-align"><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>npm</code></td><td align="left"><a href="https://registry.npmjs.org/">https://registry.npmjs.org/</a></td></tr><tr><td align="left"><code>yarn</code></td><td align="left"><a href="https://registry.yarnpkg.com/">https://registry.yarnpkg.com/</a></td></tr><tr><td align="left"><code>tencent</code></td><td align="left"><a href="https://mirrors.cloud.tencent.com/npm/">https://mirrors.cloud.tencent.com/npm/</a></td></tr><tr><td align="left"><code>cnpm</code></td><td align="left"><a href="https://r.cnpmjs.org/">https://r.cnpmjs.org/</a></td></tr><tr><td align="left"><code>taobao</code></td><td align="left"><a href="https://registry.npmmirror.com/">https://registry.npmmirror.com/</a></td></tr><tr><td align="left"><code>npmMirror</code></td><td align="left"><a href="https://skimdb.npmjs.com/registry/">https://skimdb.npmjs.com/registry/</a></td></tr></tbody></table>
<!--rehype:className=left-align-->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="npmignore"><a aria-hidden="true" tabindex="-1" href="#npmignore"><span class="icon icon-link"></span></a><code>.npmignore</code></h3><div class="wrap-body">
<p>将下面内容存放到 <code>.npmignore</code> 文件中,放置在项目的根目录中。</p>
<pre class="language-gitignore"><code class="language-gitignore code-highlight"><span class="code-line"><span class="token entry string">.git</span>

View File

@ -26,22 +26,24 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
<path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js?v=1.5.5"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="pnpm-备忘清单"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 17h4v4h-4z"></path>
<path d="M10 17h4v4h-4z"></path>
<path d="M17 17h4v4h-4z"></path>
<path d="M17 10h4v4h-4z"></path>
<path d="M17 3h4v4h-4z"></path>
<path d="M10 10h4v4h-4z"></path>
<path d="M10 3h4v4h-4z"></path>
<path d="M3 3h4v4h-4z"></path>
</svg>
<a aria-hidden="true" tabindex="-1" href="#pnpm-备忘清单"><span class="icon icon-link"></span></a>pnpm 备忘清单</h1><div class="wrap-body">
</button><script src="../js/dark.js?v=1.5.5"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="pnpm-备忘清单"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 156 156">
<g fill="none" fill-rule="evenodd">
<polygon fill="#F9AD00" fill-rule="nonzero" points="155.808 48.684 107.027 48.684 107.027 -.097 155.808 -.097"></polygon>
<polygon fill="#F9AD00" fill-rule="nonzero" points="102.139 48.684 53.358 48.684 53.358 -.097 102.139 -.097"></polygon>
<polygon fill="#F9AD00" fill-rule="nonzero" points="48 48.684 0 48.684 0 -.097 48 -.097"></polygon>
<polygon fill="#F9AD00" fill-rule="nonzero" points="155.808 102.344 107.027 102.344 107.027 53.562 155.808 53.562"></polygon>
<polygon fill="#4E4E4E" fill-rule="nonzero" points="102.139 102.344 53.358 102.344 53.358 53.562 102.139 53.562"></polygon>
<polygon fill="#4E4E4E" fill-rule="nonzero" points="102.139 156.003 53.358 156.003 53.358 107.222 102.139 107.222"></polygon>
<polygon fill="#4E4E4E" fill-rule="nonzero" points="155.808 156.003 107.027 156.003 107.027 107.222 155.808 107.222"></polygon>
<polygon fill="#4E4E4E" fill-rule="nonzero" points="48 156.003 0 156.003 0 107.222 48 107.222"></polygon>
</g>
</svg><a aria-hidden="true" tabindex="-1" href="#pnpm-备忘清单"><span class="icon icon-link"></span></a>pnpm 备忘清单</h1><div class="wrap-body">
<p>这是一份 <a href="https://pnpm.io/"><code>pnpm</code></a> 软件包管理器备忘单,其中列出了 <code>pnpm</code> 常用命令使用清单。</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-与-npm-命令比较">pnpm 与 npm 命令比较</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-install">pnpm install</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-add">pnpm add</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-remove">pnpm remove</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-update">pnpm update</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-list">pnpm list</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-cache">pnpm cache</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-why">pnpm why</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#示例">示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装包">安装包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#移除包">移除包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#查看包">查看包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#清除">清除</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#信息">信息</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#清理缓存">清理缓存</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#monorepo">Monorepo</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建-monorepo-工作区">创建 Monorepo 工作区</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加包到-monorepo-工作区">添加包到 Monorepo 工作区</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运行脚本">运行脚本</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加工作区范围的依赖">添加工作区范围的依赖</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建新的包">创建新的包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#链接本地包">链接本地包</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#高级用法">高级用法</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#工作区">工作区</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#链接">链接</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运行脚本-1">运行脚本</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-与-npm-命令比较"><a aria-hidden="true" tabindex="-1" href="#pnpm-与-npm-命令比较"><span class="icon icon-link"></span></a>pnpm 与 npm 命令比较</h3><div class="wrap-body">
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-与-npm-命令比较">pnpm 与 npm 命令比较</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-list">pnpm list</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-why">pnpm why</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-install">pnpm install</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-add">pnpm add</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-update">pnpm update</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-remove">pnpm remove</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pnpm-cache">pnpm cache</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#示例">示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装包">安装包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#移除包">移除包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#查看包">查看包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#清除">清除</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#信息">信息</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#清理缓存">清理缓存</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#monorepo">Monorepo</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建-monorepo-工作区">创建 Monorepo 工作区</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加包到-monorepo-工作区">添加包到 Monorepo 工作区</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运行脚本">运行脚本</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加工作区范围的依赖">添加工作区范围的依赖</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建新的包">创建新的包</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#链接本地包">链接本地包</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#高级用法">高级用法</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#工作区">工作区</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#链接">链接</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运行脚本-1">运行脚本</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="pnpm-与-npm-命令比较"><a aria-hidden="true" tabindex="-1" href="#pnpm-与-npm-命令比较"><span class="icon icon-link"></span></a>pnpm 与 npm 命令比较</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
@ -83,36 +85,7 @@
<table><thead><tr><th align="left">npm</th><th align="left">pnpm</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left"><code>npm install</code></td><td align="left"><code>pnpm install</code></td><td align="left">安装依赖</td></tr><tr><td align="left"><code>npm init</code></td><td align="left"><code>pnpm init</code></td><td align="left">创建 <code>package.json</code> 文件</td></tr><tr><td align="left"><code>npm install &#x3C;package></code></td><td align="left"><code>pnpm add &#x3C;package></code></td><td align="left">安装包</td></tr><tr><td align="left"><code>npm install -g &#x3C;package></code></td><td align="left"><code>pnpm add -g &#x3C;package></code></td><td align="left">全局安装包</td></tr><tr><td align="left"><code>npm update</code></td><td align="left"><code>pnpm update</code></td><td align="left">更新包</td></tr><tr><td align="left"><code>npm cache clean</code></td><td align="left"><code>pnpm cache clean</code></td><td align="left">清理缓存</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-install"><a aria-hidden="true" tabindex="-1" href="#pnpm-install"><span class="icon icon-link"></span></a>pnpm install</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">--no-lockfile <span class="token comment"># 不生成 pnpm-lock.yaml 锁定文件</span>
</span><span class="code-line"><span class="token parameter variable">--force</span> <span class="token comment"># 强制覆盖现有的 node_modules</span>
</span><span class="code-line">--frozen-lockfile <span class="token comment"># 忽略 pnpm-lock.yaml 中的更改</span>
</span><span class="code-line"><span class="token parameter variable">--offline</span> <span class="token comment"># 离线模式,不尝试从远程仓库安装包</span>
</span><span class="code-line">--shamefully-hoist <span class="token comment"># 类似于 npm 的 hoist 行为</span>
</span><span class="code-line">--strict-peer-dependencies <span class="token comment"># 严格检查 peer dependencies</span>
</span></code></pre>
<p>这些选项可用于 <code>pnpm install</code></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-add"><a aria-hidden="true" tabindex="-1" href="#pnpm-add"><span class="icon icon-link"></span></a>pnpm add</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token parameter variable">--save</span> <span class="token comment"># 将包添加到 dependencies</span>
</span><span class="code-line">--save-dev <span class="token comment"># 将包添加到 devDependencies</span>
</span><span class="code-line"><span class="token parameter variable">--global</span> <span class="token comment"># 全局安装包</span>
</span><span class="code-line"><span class="token parameter variable">--exact</span> <span class="token comment"># 安装精确版本号的包</span>
</span><span class="code-line">--shamefully-hoist <span class="token comment"># 类似于 npm 的 hoist 行为</span>
</span><span class="code-line">--strict-peer-dependencies <span class="token comment"># 严格检查 peer dependencies</span>
</span></code></pre>
<p>这些选项可用于 <code>pnpm add</code></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-remove"><a aria-hidden="true" tabindex="-1" href="#pnpm-remove"><span class="icon icon-link"></span></a>pnpm remove</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 从依赖中删除包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-update"><a aria-hidden="true" tabindex="-1" href="#pnpm-update"><span class="icon icon-link"></span></a>pnpm update</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 更新所有包</span>
</span><span class="code-line"><span class="token function">pnpm</span> update
</span><span class="code-line"><span class="token comment"># 更新特定包</span>
</span><span class="code-line"><span class="token function">pnpm</span> update <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span><span class="code-line"><span class="token comment"># 更新到最新版本(包括 major 版本)</span>
</span><span class="code-line"><span class="token function">pnpm</span> update <span class="token parameter variable">--latest</span>
</span></code></pre>
<p>参考 <a href="./npm.html">npm</a> 备忘清单</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-list"><a aria-hidden="true" tabindex="-1" href="#pnpm-list"><span class="icon icon-link"></span></a>pnpm list</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 列出所有已安装的包</span>
</span><span class="code-line"><span class="token function">pnpm</span> list
@ -121,16 +94,108 @@
</span><span class="code-line"><span class="token comment"># 查找过时的包</span>
</span><span class="code-line"><span class="token function">pnpm</span> outdated
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-why"><a aria-hidden="true" tabindex="-1" href="#pnpm-why"><span class="icon icon-link"></span></a>pnpm why</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 显示为什么安装了某个包</span>
</span><span class="code-line"><span class="token function">pnpm</span> why <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="pnpm-install"><a aria-hidden="true" tabindex="-1" href="#pnpm-install"><span class="icon icon-link"></span></a>pnpm install</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<table class="style-list-arrow"><thead><tr><th align="left">pnpm</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left"><code>--no-lockfile</code></td><td align="left">不生成 pnpm-lock.yaml 锁定文件</td></tr><tr><td align="left"><code>--force</code></td><td align="left">强制覆盖现有的 node_modules</td></tr><tr><td align="left"><code>--frozen-lockfile</code></td><td align="left">忽略 pnpm-lock.yaml 中的更改</td></tr><tr><td align="left"><code>--offline</code></td><td align="left">离线模式,不尝试从远程仓库安装包</td></tr><tr><td align="left"><code>--shamefully-hoist</code></td><td align="left">类似于 npm 的 hoist 行为</td></tr><tr><td align="left"><code>--strict-peer-dependencies</code></td><td align="left">严格检查 peer dependencies</td></tr></tbody></table>
<!--rehype:className=style-list-arrow-->
<p>这些选项可用于 <code>pnpm install</code></p>
</div></div></div><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="pnpm-add"><a aria-hidden="true" tabindex="-1" href="#pnpm-add"><span class="icon icon-link"></span></a>pnpm add</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<table class="style-list-arrow"><thead><tr><th align="left">pnpm</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left"><code>--save</code></td><td align="left">将包添加到 dependencies</td></tr><tr><td align="left"><code>--save-dev</code></td><td align="left">将包添加到 devDependencies</td></tr><tr><td align="left"><code>--global</code></td><td align="left">全局安装包</td></tr><tr><td align="left"><code>--exact</code></td><td align="left">安装精确版本号的包</td></tr><tr><td align="left"><code>--shamefully-hoist</code></td><td align="left">类似于 npm 的 hoist 行为</td></tr><tr><td align="left"><code>--strict-peer-dependencies</code></td><td align="left">严格检查 peer dependencies</td></tr></tbody></table>
<!--rehype:className=style-list-arrow-->
<p>这些选项可用于 <code>pnpm add</code></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-update"><a aria-hidden="true" tabindex="-1" href="#pnpm-update"><span class="icon icon-link"></span></a>pnpm update</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 更新所有包</span>
</span><span class="code-line"><span class="token function">pnpm</span> update
</span><span class="code-line"><span class="token comment"># 更新特定包</span>
</span><span class="code-line"><span class="token function">pnpm</span> update <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span><span class="code-line"><span class="token comment"># 更新到最新版本(包括 major 版本)</span>
</span><span class="code-line"><span class="token function">pnpm</span> update <span class="token parameter variable">--latest</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-remove"><a aria-hidden="true" tabindex="-1" href="#pnpm-remove"><span class="icon icon-link"></span></a>pnpm remove</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 从依赖中删除包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span><span class="code-line"><span class="token comment"># 删除全局依赖包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove <span class="token parameter variable">-g</span> create-react-app
</span><span class="code-line"><span class="token comment"># 删除特定版本的依赖包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove lodash@4.17.21
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-cache"><a aria-hidden="true" tabindex="-1" href="#pnpm-cache"><span class="icon icon-link"></span></a>pnpm cache</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 清理 pnpm 缓存</span>
</span><span class="code-line"><span class="token function">pnpm</span> cache clean
</span><span class="code-line"><span class="token comment"># 查看缓存中所有的包</span>
</span><span class="code-line"><span class="token function">pnpm</span> cache list
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pnpm-why"><a aria-hidden="true" tabindex="-1" href="#pnpm-why"><span class="icon icon-link"></span></a>pnpm why</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 显示为什么安装了某个包</span>
</span><span class="code-line"><span class="token function">pnpm</span> why <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="示例"><a aria-hidden="true" tabindex="-1" href="#示例"><span class="icon icon-link"></span></a>示例</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="安装包"><a aria-hidden="true" tabindex="-1" href="#安装包"><span class="icon icon-link"></span></a>安装包</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 将包添加到“dependencies”</span>
@ -146,6 +211,12 @@
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="移除包"><a aria-hidden="true" tabindex="-1" href="#移除包"><span class="icon icon-link"></span></a>移除包</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">pnpm</span> remove <span class="token operator">&#x3C;</span>package<span class="token operator">></span>
</span><span class="code-line"><span class="token comment"># 删除多个依赖包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove lodash express
</span><span class="code-line"><span class="token comment"># 删除全局依赖包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove <span class="token parameter variable">-g</span> create-react-app
</span><span class="code-line"><span class="token comment"># 删除特定版本的依赖包</span>
</span><span class="code-line"><span class="token function">pnpm</span> remove lodash@4.17.21
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="查看包"><a aria-hidden="true" tabindex="-1" href="#查看包"><span class="icon icon-link"></span></a>查看包</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 列出已安装的包</span>
@ -173,29 +244,35 @@
</span></code></pre>
<p>此外,您可以指定一个或多个要清理的包。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="monorepo"><a aria-hidden="true" tabindex="-1" href="#monorepo"><span class="icon icon-link"></span></a>Monorepo</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建-monorepo-工作区"><a aria-hidden="true" tabindex="-1" href="#创建-monorepo-工作区"><span class="icon icon-link"></span></a>创建 Monorepo 工作区</h3><div class="wrap-body">
<ol>
<li>创建一个新的 pnpm 工作区:</li>
</ol>
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="创建-monorepo-工作区"><a aria-hidden="true" tabindex="-1" href="#创建-monorepo-工作区"><span class="icon icon-link"></span></a>创建 Monorepo 工作区</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<ul class="style-timeline">
<li>
<p>创建一个新的 pnpm 工作区:</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">pnpm</span> init <span class="token parameter variable">-w</span>
</span></code></pre>
<p>这将在项目的根目录中创建一个 <code>pnpm-workspace.yaml</code> 文件,内容如下:</p>
</li>
<li>
<p>将在项目的根目录中创建一个 <code>pnpm-workspace.yaml</code> 文件,内容如下:</p>
<pre class="language-yaml"><code class="language-yaml code-highlight"><span class="code-line"><span class="token key atrule">packages</span><span class="token punctuation">:</span>
</span><span class="code-line"> <span class="token punctuation">-</span> <span class="token string">'packages/**'</span>
</span><span class="code-line"> <span class="token punctuation">-</span> <span class="token string">'apps/**'</span>
</span></code></pre>
<ol start="2">
<li><code>pnpm-workspace.yaml</code> 中定义您的工作区结构:</li>
</ol>
</li>
<li>
<p><code>pnpm-workspace.yaml</code> 中定义您的工作区结构:</p>
<pre class="language-yaml"><code class="language-yaml code-highlight"><span class="code-line"><span class="token key atrule">packages</span><span class="token punctuation">:</span>
</span><span class="code-line"> <span class="token punctuation">-</span> <span class="token string">'packages/*'</span>
</span><span class="code-line"> <span class="token punctuation">-</span> <span class="token string">'apps/*'</span>
</span></code></pre>
</li>
</ul>
<!--rehype:className=style-timeline-->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="添加包到-monorepo-工作区"><a aria-hidden="true" tabindex="-1" href="#添加包到-monorepo-工作区"><span class="icon icon-link"></span></a>添加包到 Monorepo 工作区</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 在工作区中添加包</span>
</span><span class="code-line"><span class="token function">pnpm</span> <span class="token function">add</span> <span class="token operator">&#x3C;</span>package<span class="token operator">></span> <span class="token parameter variable">-w</span>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">pnpm</span> <span class="token function">add</span> <span class="token operator">&#x3C;</span>package<span class="token operator">></span> <span class="token parameter variable">-w</span> <span class="token comment"># 在工作区中添加包</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="运行脚本"><a aria-hidden="true" tabindex="-1" href="#运行脚本"><span class="icon icon-link"></span></a>运行脚本</h3><div class="wrap-body">
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="运行脚本"><a aria-hidden="true" tabindex="-1" href="#运行脚本"><span class="icon icon-link"></span></a>运行脚本</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 在所有包中运行脚本</span>
</span><span class="code-line"><span class="token function">pnpm</span> <span class="token parameter variable">-r</span> run <span class="token operator">&#x3C;</span>script<span class="token operator">></span>
</span><span class="code-line"><span class="token comment"># 仅在某个包中运行脚本</span>