Tru*_*Gao 5 npm node-modules monorepo npm-workspaces
以下是一些相关问题:
\n使用yarn工作空间时,如何强制将包安装在相关的node_modules中?
\n\n我是否应该对带有react-native-web的monorepo中的所有包使用no-hoist?
\n我正在使用 npm 工作区来组织多个包。问题是我的主包在本地 node_modules 中没有其依赖项(也是工作区之一)源代码。我知道依赖项安装在根 node_modules 中,问题是我需要通过主包的相对路径访问它。
\nnpm install这是在根目录下运行后的项目结构:
root\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json -> { "workspaces": ["packages/*"] }\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 node_modules\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency-A\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency-B\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 packages\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main-package\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency-A\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 dependency-B\nRun Code Online (Sandbox Code Playgroud)\n根目录中的package.json:
\nroot\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json -> { "workspaces": ["packages/*"] }\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 node_modules\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency-A\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency-B\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 packages\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main-package\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency-A\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 dependency-B\nRun Code Online (Sandbox Code Playgroud)\n“packages/main-package”中的 package.json:
\n{\n "workspaces": [\n "packages/main-package",\n "packages/dependency-A",\n "packages/dependency-B"\n ]\n}\n\nRun Code Online (Sandbox Code Playgroud)\nwebpack.config.js 在“packages/main-package”中:
\n{\n "dependencies": {\n "dependency-A": "0.1.0",\n "dependency-B": "0.1.0"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n当我在 main-package 中运行 webapck 时,错误消息是:
\n{\n plugins: [\n new CopyWebpackPlugin({\n patterns: [\n {\n from: "node_modules/dependency-A/media",\n to: "static/dependency-A-media",\n },\n ],\n }),\n new CopyWebpackPlugin({\n patterns: [\n {\n context: "node_modules/dependency-B/dist",\n from: "research-data.json",\n },\n ],\n }),\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\n我想知道解决此类问题的最佳实践是什么?Yarn 的“nohoist”选项启发了我,但我在 npm 中找不到它。我还尝试在包目录中运行安装,但它会破坏它们的符号链接。如何在本地 node_modules 中安装每个包的依赖项,同时维护它们的链接(如 lerna@4)?
\n尝试过的版本:\nnode.js@16.13.0\nnpm@8.1.0\n&\nnode.js@18.14.0\nnpm@9.3.1
\n希望我能用我糟糕的英语表达清楚,哈哈,非常感谢。
\n| 归档时间: |
|
| 查看次数: |
2165 次 |
| 最近记录: |