我有 package.json
文件,其中包含 10 个依赖项,
每次我执行npm install -g
时,所有依赖项都会再次下载,这需要很长时间。
有没有办法从本地 node_modules
目录获取现有依赖项?
这是我的package.json
依赖项:
"dependencies": {
"body-parser": "~1.16.0",
"colors": "^1.1.2",
"console-stamp": "^0.2.5",
"cookie-parser": "~1.4.3",
"dateformat": "^2.0.0",
"debug": "~2.6.0",
"express": "~4.14.1",
"ip": "^1.1.5",
"jade": "~1.11.0",
"lodash": "^4.17.4",
"morgan": "~1.7.0",
"nodemon": "^1.11.0",
"promise": "^8.0.1",
"rand-token": "^0.3.0",
"random-date-generator": "^1.0.2",
"restify": "^4.3.0",
"restify-cookies": "^0.2.2",
"serve-favicon": "~2.3.2"
}
谢谢
最佳答案
npm install -g
将当前包上下文(即当前工作目录)安装为全局包。您不需要使用它来安装项目依赖项。相反,您可以使用 npm install
它将在 node_modules 文件夹中安装/更新依赖项。默认情况下,npm install
将安装 package.json
中列为依赖项的所有模块,并且它们不会每次都安装所有依赖项,只有在对 package.json
进行更改或清除 node_modules
文件夹时才会更新。
使用npm install -g
选项全局安装包,如cordova、gulp、yeoman等,您需要它们在多个项目中可用。
关于node.js - npm install -g 再次下载所有依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49107972/