--save和--save-dev有什么区别?

本文翻译自:What is the difference between --save and --save-dev?

What is the difference between: 有什么区别:

npm install [package_name] --save npm install [package_name] --save

and

npm install [package_name] --save-dev npm install [package_name] --save-dev

What does this mean? 这是什么意思?


#1楼

参考:https://stackoom.com/question/1Y335/save和-save-dev有什么区别


#2楼

--save-dev节省semver规范到你的包描述符文件“devDependencies”排列, --save它保存到“依存关系”代替。


#3楼

As suggested by @andreas-hultgren in this answer and according to the npm docs : 正如@ andreas-hultgren在这个答案和根据npm文档所建议的那样

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. 如果有人计划在他们的程序中下载和使用您的模块,那么他们可能不希望或不需要下载和构建您使用的外部测试或文档框架。

However, for webapp development, Yeoman (a scaffolding tool that installs a peer-reviewed, pre-written package.json file amongst other things) places all packages in devDependencies and nothing in dependencies, so it appears that the use of --save-dev is a safe bet in webapp development, at least. 但是,对于webapp开发, Yeoman (一个脚手架工具,安装一个经过同行评审,预先编写的package.json文件等)将所有包放在devDependencies中而不依赖于任何东西,因此看起来使用了--save-devwebapp开发中的一个安全的赌注,至少。


#4楼

  • --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用于保存应用程序运行所需的包。

#5楼

The difference between --save and --save-dev may not be immediately noticeable if you have tried them both on your own projects. 如果您在自己的项目中尝试过它们,那么--save--save-dev之间的区别可能不会立即引起注意。 So here are a few examples... 所以这里有几个例子......

Lets say you were building an app that used the moment package to parse and display dates. 让我们假设您正在构建一个使用时刻包来解析和显示日期的应用程序。 Your app is a scheduler so it really needs this package to run, as in: cannot run without it . 您的应用程序是一个调度程序,因此它确实需要运行此程序包,如: 没有它就无法运行 In this case you would use 在这种情况下,你会使用

npm install moment --save

This would create a new value in your package.json 这将在package.json中创建一个新值

"dependencies": {
   ...
   "moment": "^2.17.1"
}

When you are developing, it really helps to use tools such as test suites and may need jasmine-core and karma . 在开发时,使用测试套件等工具确实很有帮助,可能需要jasmine-corekarma In this case you would use 在这种情况下,你会使用

npm install jasmine-core --save-dev
npm install karma --save-dev

This would also create a new value in your package.json 这也会在package.json中创建一个新值

"devDependencies": {
    ...
    "jasmine-core": "^2.5.2",
    "karma": "^1.4.1",
}

You do not need the test suite to run the app in its normal state, so it is a --save-dev type dependency, nothing more. 不需要测试套件以正常状态运行应用程序,因此它是--save-dev类型依赖项,仅此而已。 You can see how if you do not understand what is really happening, it is a bit hard to imagine. 你可以看到,如果你不理解真正发生的事情,有点难以想象。

Taken directly from NPM docs docs#dependencies 直接取自NPM docs docs#dependencies

Dependencies 依赖

Dependencies are specified in a simple object that maps a package name to a version range. 依赖关系在将包名称映射到版本范围的简单对象中指定。 The version range is a string which has one or more space-separated descriptors. 版本范围是一个字符串,其中包含一个或多个以空格分隔的描述符。 Dependencies can also be identified with a tarball or git URL. 也可以使用tarball或git URL识别依赖关系。

Please do not put test harnesses or transpilers in your dependencies object. 请不要在依赖项对象中放置测试工具或转换器。 See devDependencies , below. 请参阅下面的devDependencies

Even in the docs, it asks you to use --save-dev for modules such as test harnesses. 即使在文档中,它也会要求您使用--save-dev来获取测试工具等模块。

I hope this helps and is clear. 我希望这有帮助并且很清楚。


#6楼

By default, NPM simply installs a package under node_modules. 默认情况下,NPM只是在node_modules下安装包。 When you're trying to install dependencies for your app/module, you would need to first install them, and then add them to the dependencies section of your package.json . 当您尝试为应用程序/模块安装依赖项时,您需要先安装它们,然后将它们添加到package.jsondependencies部分。

--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它。

--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 package . 只要有人运行npm install package它就会与软件包一起npm install package

Dev dependencies are those dependencies that are only needed for developing the package. Dev依赖项是仅在开发包时需要的依赖项。 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 --save-dev添加到devDependencies

npm install documentation can be referred here. npm安装文档可以在这里参考。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章