【发布时间】:2014-12-31 12:01:25
【问题描述】:
例如,为什么 Grunt 插件将其对 grunt 的依赖定义为“peer dependencies”?
为什么插件不能在 grunt-plug/node_modules 中将 Grunt 作为自己的依赖项?
此处描述了对等依赖项:https://nodejs.org/en/blog/npm/peer-dependencies/
但我真的不明白。
示例
我目前正在使用 AppGyver Steroids,它使用 Grunt 任务将我的源文件构建到 /dist/ 文件夹中,以便在本地设备上提供服务。我在 npm 和 grunt 上很新,所以我想完全理解发生了什么。
到目前为止,我得到了这个:
[rootfolder]/package.json 告诉 npm 它依赖于 grunt-steroids npm 包进行开发:
"devDependencies": {
"grunt-steroids": "0.x"
},
好的。在 [rootfolder] 中运行 npm install 会检测到依赖关系并在 [rootfolder]/node_modules/grunt-steroids 中安装 grunt-steroids。
Npm 然后读取 [rootfolder]/node_modules/grunt-steroids/package.json 以便它可以安装 grunt-steroids 自己的依赖项。:
"devDependencies": {
"grunt-contrib-nodeunit": "0.3.0",
"grunt": "0.4.4"
},
"dependencies": {
"wrench": "1.5.4",
"chalk": "0.3.0",
"xml2js": "0.4.1",
"lodash": "2.4.1"
},
"peerDependencies": {
"grunt": "0.4.4",
"grunt-contrib-copy": "0.5.0",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-concat": "0.4.0",
"grunt-contrib-coffee": "0.10.1",
"grunt-contrib-sass": "0.7.3",
"grunt-extend-config": "0.9.2"
},
“dependencies”软件包安装到 [rootfolder]/node_modules/grunt-steroids/node_modules 中,这对我来说是合乎逻辑的。
没有安装“devDependencies”,我确定它是由 npm 控制的,检测我只是想使用grunt-steroids,而不是在上面开发。
但是我们有“peerDependencies”。
这些安装在 [rootfolder]/node_modules 中,我不明白为什么没有安装在 [rootfolder]/node_modules/grunt-steroids/node_modules 中所以避免与其他 grunt 插件(或其他)冲突?
【问题讨论】:
标签: node.js npm package-managers