有什么方法可以将 npm install 路由到硬盘驱动器的特定部分,当我执行 npm install 时,它会在驱动器的那个部分创建 node_module 文件夹,当我运行任何项目时,它会在驱动器的那个部分寻找依赖项, 就像每个项目都有一个池。
然后,如果我有两个具有相似依赖关系的项目,那么我只需要在一个项目中npm install
,这样依赖项就可以在pool中使用,而无需执行npm install
在另一个项目中只是 npm start
谢谢, 因扎马姆·马利克
最佳答案
您可以通过 link
选项实现与您所描述的接近的效果。
来自 https://docs.npmjs.com/misc/config#link :
If true, then local installs will link if there is a suitable globally installed package.
Note that this means that local installs can cause things to be installed into the global space at the same time. The link is only done if one of the two conditions are met:
- The package is not already installed globally, or
- the globally installed version is identical to the version that is being installed locally.
所以你仍然会在每个项目的 node_modules
中有一些文件,但你不应该有那么大的文件夹。
要打开这个行为,运行:
npm config set link -g
编辑:您无法避免运行 npm install
并拥有一个 node_modules
文件夹。 Node.js 总是在 node_modules
中查找依赖项(此行为早于 npm
本身)。 link
选项将使 npm
在 node_modules
中创建符号链接(symbolic link),指向一个公共(public)池。这将减少磁盘使用,但您不能取消 node_modules
。
关于node.js - 为每个项目执行 npm install 会占用太多驱动器空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42781991/