javascript - npm install --save 和 npm install --save-dev 之间的区别

标签 javascript npm

伙计们,我知道使用 npm install -g 我们可以全局安装节点模块/包,但我不确定选项 --save--保存开发

我用谷歌搜索了一下,但还是不太清楚。请分享您的想法。

最佳答案

--save 将第三方包添加到包的依赖项。每当有人运行 npm install yourPackage 时,它将与包一起安装。

--save-dev 将第三方包添加到包的开发依赖项。当有人安装你的包时,它不会被安装。它通常只有在有人克隆您的源存储库并在其中运行 npm install 时才会安装。

Dev dependencies,顾名思义,就是那些只在开发包时需要的依赖。这可以包括测试运行器、编译器、打包器等。

这两种类型的依赖项都存储在包的 package.json 文件中。 --save 添加到dependencies--save-dev 添加到devDependenciesFrom 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.

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. See npm-config(7) for more on the topic.

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.

编辑:截至 npm 5.0.0安装的模块默认添加为依赖项,因此不再需要 --save 选项。

关于javascript - npm install --save 和 npm install --save-dev 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33055375/

相关文章:

Javascript 不适用于 ajax 生成的代码?

javascript - 为什么 Azure 服务器响应错误请求?

node.js - 如何更新 github 上的 npm 包

javascript - 使用 javascript 循环月份

javascript - 如何删除在 TypeScript 中使用 "this"的事件监听器?

javascript - 创建 Ruby Gem 以将 HTML/JavaScript 插入主应用程序

node.js - 在 Jenkins 中运行时,NPM 测试神秘地卡住了

node.js - 无法设置node.js环境

node.js - ansible npm install 永远不会完成

javascript - React - 异步 api 调用,Promise.all 等待调用完成