简体   繁体   English

npm install --save 和 npm install --save-dev 的区别

[英]Difference between npm install --save and npm install --save-dev

Guys I know that using npm install -g we can install the node modules/packages globally, but I am not sure about the options --save and --save-dev伙计们,我知道使用npm install -g我们可以全局安装节点模块/包,但我不确定选项--save--save-dev

I have Googled it but still not clear about it.我已经谷歌了它,但仍然不清楚。 Please share your thoughts.请分享您的想法。

--save adds the third-party package to the package's dependencies . --save将第三方包添加到包的依赖项中 It will be installed together with the package whenever someone runs npm install yourPackage .每当有人运行npm install yourPackage时,它将与包一起npm install yourPackage

--save-dev adds the third-party package to the package's development dependencies . --save-dev将第三方包添加到包的开发依赖项中 It won't be installed when someone installs your package.当有人安装您的软件包时,它不会被安装。 It's typically only installed if someone clones your source repository and runs npm install in it.它通常仅在有人克隆您的源存储库并在其中运行npm install时才会npm install

Dev dependencies, as the same suggests, are those dependencies that are only needed for developing the package.正如所暗示的那样,开发依赖项是那些仅在开发包时需要的依赖项。 That can include test runners, compilers, packagers, etc.这可以包括测试运行器、编译器、打包器等。

Both types of dependencies are stored in the package's package.json file.两种类型的依赖项都存储在包的package.json文件中。 --save adds to dependencies , --save-dev adds to devDependencies . --save添加到dependencies--save-dev添加到devDependencies From the documentation :从文档

devDependencies开发依赖

If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.如果有人计划在他们的程序中下载和使用您的模块,那么他们可能不想或不需要下载和构建您使用的外部测试或文档框架。

In this case, it's best to map these additional items in a devDependencies object.在这种情况下,最好将这些附加项映射到 devDependencies 对象中。

These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param.这些东西将在从包的根目录执行 npm link 或 npm install 时安装,并且可以像任何其他 npm 配置参数一样进行管理。 See npm-config(7) for more on the topic.有关该主题的更多信息,请参阅 npm-config(7)。

For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.对于非特定于平台的构建步骤,例如将 CoffeeScript 或其他语言编译为 JavaScript,请使用预发布脚本来执行此操作,并使所需的包成为 devDependency。

Edit: As of npm 5.0.0 the installed modules are added as a dependency by default, so the --save option is no longer needed.编辑:从npm 5.0.0 开始,安装的模块默认添加为依赖项,因此不再需要 --save 选项。

  • --save-dev is used to save the package for development purpose. --save-dev用于保存用于开发目的的包。 Example: unit tests, minification.示例:单元测试、缩小。
  • --save is used to save the package required for the application to run. --save用于保存应用程序运行所需的包。
  1. --save-dev will save npm modules in development dependencies in package.json ie it will save inside devDependencies object. --save-dev将 npm 模块保存在 package.json 中的开发依赖项中,即它将保存在 devDependencies 对象中。
  2. --save will save npm modules dependencies in package.json ie it will save inside dependencies object. --save将在 package.json 中保存 npm 模块依赖项,即它将保存在依赖项对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 npm install lite-server --save-dev 安装错误 - npm install lite-server --save-dev installation error 以编程方式安装npm包,提供--save-dev标志 - Programmatically install a npm package, providing --save-dev flag 如果我使用“ npm install --save-dev”进行NPM安装,如何检查更新 - If I do an NPM install with “npm install --save-dev” how can I check for updates 是不是npm install -save-dev gulp-uglify与npm install gulp-uglify不同 - Is npm install --save-dev gulp-uglify different to npm install gulp-uglify 'npm add'和'npm install --save'之间的区别? - Difference between 'npm add' and 'npm install --save'? 安装npm install --save-dev web3@1.0.0-beta.26错误? - Installing npm install --save-dev web3@1.0.0-beta.26 error? npm 安装错误:rollbackFailedOptional:动词 npm-session a0d68 用于命令 npm install --save-dev @babel/core @babel/cli - npm install error: rollbackFailedOptional: verb npm-session a0d68 for command npm install --save-dev @babel/core @babel/cli Gulp:npm install gulp --save-dev期望只在node_modules文件夹内看到一个gulp文件夹 - Gulp: npm install gulp --save-dev was expecting to see just a gulp folder inside the node_modules folder “Npm install --global”和“--save”在一起吗? - “Npm install --global” and “--save” together? `npm install`和`npm audit`之间的区别是什么? - Difference between `npm install` and `npm audit` counts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM