What do the --save flags do with npm install

后端 未结 3 1436
遇见更好的自我
遇见更好的自我 2021-01-30 09:46

I see instructions to install a package with either

npm install 

or

npm install  --save         


        
3条回答
  •  遇见更好的自我
    2021-01-30 10:22

    The --save flag no longer serves a purpose.

    Previously, as the other answers noted, the --save flag would update the dependencies in the project's package.json file, but npm install now includes this functionality by default.

    At this point if you want to prevent npm install from saving dependencies, you have to use the --no-save flag.

    Thanks to Coruscate5 for mentioning this in their comment.

    More info in the npm-install documentation:

    npm install saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:

    -P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.

    -D, --save-dev: Package will appear in your devDependencies.

    -O, --save-optional: Package will appear in your optionalDependencies.

    --no-save: Prevents saving to dependencies.

    When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:

    -E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm’s default semver range operator.

    -B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.

提交回复
热议问题