小编Tru*_*Gao的帖子

使用npm工作区时,如何强制将包安装在相关的node_modules中?

以下是一些相关问题:

\n

使用yarn工作空间时,如何强制将包安装在相关的node_modules中?

\n

NPM 7 工作区 - 多个 node_modules?

\n

我是否应该对带有react-native-web的monorepo中的所有包使用no-hoist?

\n

我正在使用 npm 工作区来组织多个包。问题是我的主包在本地 node_modules 中没有其依赖项(也是工作区之一)源代码。我知道依赖项安装在根 node_modules 中,问题是我需要通过主包的相对路径访问它。

\n

npm install这是在根目录下运行后的项目结构:

\n
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\n
Run Code Online (Sandbox Code Playgroud)\n

根目录中的package.json:

\n
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\n
Run 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\n
Run Code Online (Sandbox Code Playgroud)\n

webpack.config.js 在“packages/main-package”中: …

npm node-modules monorepo npm-workspaces

5
推荐指数
0
解决办法
2165
查看次数

标签 统计

monorepo ×1

node-modules ×1

npm ×1

npm-workspaces ×1