Is it okay to include npm in devdependencies in package.json?

爷,独闯天下 提交于 2019-12-13 03:48:40

问题


I came across a nodejs repo that included npm in devdependencies. What would be the case that requires such config? Because, installing devdependencies already requires npm.


回答1:


This makes sense if a repository uses NPM CLI internally and relies on specific NPM version instead of globally installed NPM, because the behaviour may be changed between major releases:

devDependencies: {
  "npm": "^2"
}

While

devDependencies: {
  "npm": "*"
}

won't make much sense, except that it will likely use latest stable NPM version, despite which version was installed globally on local system.

This also makes sense if NPM is used programmatically because global packages cannot be normally required.




回答2:


Modules which is required for your local development and does not required for production environment can be listed under devDependencies. Its is good to have devDependencies.

  • npm install will install both "dependencies" and "devDependencies"
  • npm install --production will only install "dependencies"
  • npm install --dev will only install "devDependencies"


来源:https://stackoverflow.com/questions/50399097/is-it-okay-to-include-npm-in-devdependencies-in-package-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!