我有一个从github私有仓库安装的私有npm模块。该模块依赖于“ axios”模块。因此,在package.json中,我已将其添加到依赖项下。
package.json 的私有模块
{
"name": "xxx",
"version": "1.0.0",
"description": "xxxx",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xxxx/yyyy.git"
},
"keywords": [
"xxxx"
],
"author": "xxxx",
"license": "ISC",
"bugs": {
"url": "https://github.com/xxx"
},
"homepage": "https://github.com/xxxxx#readme",
"dependencies": {
"axios": "latest"
}
}
我也在“ index.js”中使用“ axios”,因此在我的根级别“ package.json”中将“ axios”列为依赖项
package.json 在根级别
{
"name": "my code",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"axios": "^0.18.0",
"xxx": "git+ssh://github.com/xxxx/yyyy.git",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
总体“ axios”在我的项目中的2个地方被列为依赖项。 当我执行npm安装时。 “ axios”将安装在两个位置。
这是执行 npm install
后我的项目结构Project | +-- index.js | +-- package.json | +-- node_modules | | | +-- axios | | | +-- xxx | | | | | +-- index.js | | | | | +-- package.json | | | | | +-- node_modules | | | | | | | +-- axios // How to avoid axios getting installed here again and make it reuse the one in root level node_modules directory