Node.js/yarn:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的9个中间版本)
第1行: 第1行:
== 标题文本 ==
[[/特殊配置|特殊配置]]
== 配置文件 ==
[[/配置文件|配置文件]]
== 安装 ==
== 安装 ==
centos
centos
第33行: 第41行:
| 官方镜像源 || https://registry.yarnpkg.com/
| 官方镜像源 || https://registry.yarnpkg.com/
|}
|}
== 验证 ==
{{shc|<syntaxhighlight lang="bash">
yarn config set npmAuthToken <yourToken></syntaxhighlight>|$|/home/kangkk}}
Token 可以在 <code>.npmrc</code> 文件中获取(需要通过 NPM 登录之后)。


=== 源工具 ===
=== 源工具 ===
第71行: 第73行:
"npmRegistryServer": "http://mirrors.cloud.tencent.com/npm/"
"npmRegistryServer": "http://mirrors.cloud.tencent.com/npm/"
</syntaxhighlight>}}
</syntaxhighlight>}}
== 配置 ==
=== unsafeHttpWhitelist ===
{{shc|<syntaxhighlight lang="bash">
yarn config set unsafeHttpWhitelist --json '["*.xxx.com"]'</syntaxhighlight>|$|/home/kangkk}}
=== npmAlwaysAuth ===
{{shc|<syntaxhighlight lang="bash">
yarn config set npmAlwaysAuth true</syntaxhighlight>|$|/home/kangkk}}
=== npmAuthToken ===
{{shc|<syntaxhighlight lang="bash">
yarn config set npmAuthToken <token></syntaxhighlight>|$|/home/kangkk}}
=== npmRegistryServer ===
{{shc|<syntaxhighlight lang="bash">
yarn config set npmRegistryServer http://npm.xxx.com</syntaxhighlight>|$|/home/kangkk}}
=== nodeLinker ===
默认值是 pnp,仍然使用 <code>node-modules</code> 文件夹。
{{shc|<syntaxhighlight lang="bash">
yarn config set nodeLinker node-modules</syntaxhighlight>|$|/home/kangkk}}
=== 私有镜像源 ===
Token 可以在 <code>.npmrc</code> 文件中获取(需要通过 NPM 登录之后)。
{{shc|<syntaxhighlight lang="bash">
yarn npm login
# or yarn config set npmAuthToken <yourToken></syntaxhighlight>|$|/home/kangkk}}


== 添加 ==
== 添加 ==
第113行: 第140行:
=== .pnp.cjs ===
=== .pnp.cjs ===
使用.pnp.cjs替代node_modules来帮助node解析包.
使用.pnp.cjs替代node_modules来帮助node解析包.
== dlx ==


== 缓存 ==
== 缓存 ==
第145行: 第174行:
yarn set version latest</syntaxhighlight>|$|/home/kangkk}}
yarn set version latest</syntaxhighlight>|$|/home/kangkk}}


== 版本升级 ==
从版本 1 升级到版本 4
{{shc|<syntaxhighlight lang="bash">
corepack enable \
&& corepack prepare yarn@4.9.2 --activate</syntaxhighlight>|$|/home/kwy}}
== 插件 ==
== 插件 ==
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
yarn plugin import workspace-tools</syntaxhighlight>|$|/home/kangkk}}
yarn plugin import workspace-tools</syntaxhighlight>|$|/home/kangkk}}
== workspaces ==
== workspaces ==


第168行: 第204行:
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
yarn workspace <workspaceName> <commandName></syntaxhighlight>|$|/home/kangkk}}
yarn workspace <workspaceName> <commandName></syntaxhighlight>|$|/home/kangkk}}
=== 子项目 ===
{{hc|head=package.json|output=<syntaxhighlight lang="bash">
...
  "packageManager": "yarn@4.4.1",
  "workspaces": [
    "athena-frontend",
    "src/next/codemirror/language/test/lezer-test"
  ]
}
</syntaxhighlight>}}
workspaces 中可以是子项目 package.json 的名称或者是相对路径,依据经验而言,对于复杂项目(子项目位置不统一)的场景,相对路径是更好的选择。