Is it okay to include npm in devdependencies in pa

2019-08-22 07:18发布

问题:

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"