问题描述
有什么方法可以将 npm install 路由到硬盘驱动器的特定部分,当我执行 npm install 时,它会在驱动器的该部分创建 node_module 文件夹,并且当我运行任何项目时,它会在驱动器的该部分查找依赖项,就像每个项目都有一个池.
is there any way to route npm install to a specific part of hard drive and when i do npm install it make node_module folder in that part of drive, and when i run any project it look for dependencies in that part of drive,just like single pool for every project.
然后,如果我有两个具有相似依赖项的项目,那么我只需要在一个项目中npm install
,这样依赖项就可以在 pool 中使用,而无需执行 npm install
在另一个项目中只是 npm start
then if i have two projects with similar dependencies then i only need to npm install
in one project so dependencies become available in pool, and no need to do npm install
in another project just npm start
谢谢,因扎曼·马利克
推荐答案
您可以使用 link
选项实现与您所描述的内容相近的内容.
You can achieve something close to what you are describing with the link
option.
来自 https://docs.npmjs.com/misc/config#link:
如果为 true,则本地安装将链接(如果有合适的全局安装包).
请注意,这意味着本地安装可能会导致同时将事物安装到全局空间中.仅当满足两个条件之一时才完成链接:
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:
- 该软件包尚未全局安装,或者
- 全局安装的版本与本地安装的版本相同.
所以你在每个项目的node_modules
中仍然会有一些文件,但你不应该有那么大的文件夹.
So you will still have some files in each project's node_modules
, but you shouldn't have as large a folder.
要打开此行为,请运行:
To turn this behavior on, run:
npm config set link -g
您无法避免运行 npm install
并拥有 node_modules
文件夹.Node.js 总是在 node_modules
中查找依赖项(此行为早于 npm
本身).link
选项将使 npm
在 node_modules
中创建符号链接,指向一个公共池.这将减少磁盘使用量,但您不能取消 node_modules
.
There is no way you can avoid running npm install
and having a node_modules
folder. Node.js always looks in node_modules
for dependencies (this behavior pre-dates npm
itself). The link
option will make npm
create symlinks in node_modules
, pointing to a common pool. That will reduce disc usage, but you cannot do away with node_modules
.
这篇关于为每个项目执行 npm install 在驱动器中占用太多空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!