伙计们,我知道使用 npm install -g
我们可以全局安装节点模块/包,但我不确定选项 --save
和 --保存开发
我用谷歌搜索了一下,但还是不太清楚。请分享您的想法。
最佳答案
--save
将第三方包添加到包的依赖项。每当有人运行 npm install yourPackage
时,它将与包一起安装。
--save-dev
将第三方包添加到包的开发依赖项。当有人安装你的包时,它不会被安装。它通常只有在有人克隆您的源存储库并在其中运行 npm install
时才会安装。
Dev dependencies,顾名思义,就是那些只在开发包时需要的依赖。这可以包括测试运行器、编译器、打包器等。
这两种类型的依赖项都存储在包的 package.json
文件中。 --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.
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/