--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安裝文檔可以在這裏參考。

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