What is the difference between --save and --save-dev?

后端 未结 13 837
旧巷少年郎
旧巷少年郎 2020-11-28 00:02

What is the difference between:

npm install [package_name]

and:

npm install [package_name] --save

and:

13条回答
  •  失恋的感觉
    2020-11-28 00:38

    You generally don't want to bloat production package with things that you only intend to use for Development purposes.

    Use --save-dev (or -D) option to separate packages such as Unit Test frameworks (jest, jasmine, mocha, chai, etc.)

    Any other packages that your app needs for Production, should be installed using --save (or -S).

    npm install --save lodash       //prod dependency
    npm install -S moment           // "       "
    npm install -S opentracing      // "       "
    
    npm install -D jest                 //dev only dependency
    npm install --save-dev typescript   //dev only dependency
    

    If you open the package.json file then you will see these entries listed under two different sections:

    "dependencies": {
      "lodash": "4.x",
      "moment": "2.x",
      "opentracing": "^0.14.1"
    },
    
    "devDependencies": {
        "jest": "22.x",
        "typescript": "^2.8.3"
    },
    

提交回复
热议问题