node.js - 为每个项目执行 npm install 会占用太多驱动器空间

标签 node.js npm

有什么方法可以将 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 选项将使 npmnode_modules 中创建符号链接(symbolic link),指向一个公共(public)池。这将减少磁盘使用,但您不能取消 node_modules

关于node.js - 为每个项目执行 npm install 会占用太多驱动器空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42781991/

相关文章:

javascript - apostrope-images-widgets 自定义小部件调用 apos.attachments.url 两次

javascript - 函数在 Cloud Functions 中返回未定义的预期 Promise 或值

npm - 通过使用 npm 安装在 webpack 中使用 particles.js

angular - 如何在 angular2-signaturePad 中修复 "Cannot read property ' toDataURL' of undefined"

node.js - 为什么 Node.js 在 node_modules 中找不到模块?

npm - 来自 npm 7 的 package-lock.json 中的 'lockfileVersion: 2' 是否与旧版本的 npm 兼容?

javascript - puppeteer:如何等待 SPA 中的页面?

node.js - nodeJs 中的 Facebook Messenger 位置

c++ - 如何检查对象是否是 Nan 2 中构造函数的实例?

node.js - (发电机 polymer )哟 polymer 失败,找不到模块 'find-index'