What is the --save option for npm install?

前端 未结 12 720
野性不改
野性不改 2020-11-22 13:54

I saw some tutorial where the command was:

npm install --save

What does the --save option mean?

Not able to find the a

相关标签:
12条回答
  • 2020-11-22 14:10

    npm i (Package name) --save

    Simplily, using above command we ll not need to write package name in your package.json file it ll auto add its name and dependency with version that you ll need at time when you go for production or setup another time.

    npm help install

    Above command ll help find out more option and correct def.shown in pic

    0 讨论(0)
  • 2020-11-22 14:11

    You can also use -S, -D or -P which are equivalent of saving the package to an app dependency, a dev dependency or prod dependency. See more NPM shortcuts below:

    -v: --version
    -h, -?, --help, -H: --usage
    -s, --silent: --loglevel silent
    -q, --quiet: --loglevel warn
    -d: --loglevel info
    -dd, --verbose: --loglevel verbose
    -ffffd: --loglevel silly
    -g: --global
    -C: --prefix
    -l: --long
    -m: --message
    -p, --porcelain: --parseable
    -reg: --registry
    -f: --force
    -desc: --description
    -S: --save
    -P: --save-prod
    -D: --save-dev
    -O: --save-optional
    -B: --save-bundle
    -E: --save-exact
    -y: --yes
    -n: --yes false
    ll and la commands: ls --long
    

    This list of shortcuts can be obtained by running the following command:

    $ npm help 7 config
    
    0 讨论(0)
  • 2020-11-22 14:11

    The easier (and more awesome) way to add dependencies to your package.json is to do so from the command line, flagging the npm install command with either --save or --save-dev, depending on how you'd like to use that dependency.

    0 讨论(0)
  • 2020-11-22 14:14

    Update npm 5:

    As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer needed. The other save options still exist and are listed in the documentation for npm install.

    Original answer:

    Before version 5, NPM simply installed a package under node_modules by default. When you were trying to install dependencies for your app/module, you would need to first install them, and then add them (along with the appropriate version number) to the dependencies section of your package.json.

    The --save option instructed NPM to include the package inside of the dependencies section of your package.json automatically, thus saving you an additional step.

    In addition, there are the complementary options --save-dev and --save-optional which save the package under devDependencies and optionalDependencies, respectively. This is useful when installing development-only packages, like grunt or your testing library.

    0 讨论(0)
  • 2020-11-22 14:17

    npm v6.x update ✅

    0 讨论(0)
  • 2020-11-22 14:18

    Update as of npm 5:

    As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer needed. The other save options still exist and are listed in the documentation for npm install.


    Original Answer:

    To add package in dependencies:

    npm install my_dep --save
    

    or

    npm install my_dep -S
    

    or

    npm i my_dep -S
    

    To add package in devDependencies

    npm install my_test_framework --save-dev
    

    or

    npm install my_test_framework -D
    

    or

    npm i my_test_framework -D
    

    package.json

    0 讨论(0)
提交回复
热议问题