weixin_41568127
?yb?
采纳率100%
2013-10-24 23:54

Npm 安装的 -- save 选项是什么?

已采纳

I saw some tutorial where the command was:

npm install --save

What does the --save option mean?

Not able to find the answer on Google.

转载于:https://stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

10条回答

  • weixin_41568183 零零乙 8年前

    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.

    点赞 25 评论 复制链接分享
  • csdnceshi71 Memor.の 7年前

    It won't do anything if you don't have a package.json file. Start by running npm init to create one. Then calls to npm install --save or npm install --save-dev or npm install --save-optional will update the package.json to list your dependencies.

    点赞 23 评论 复制链接分享
  • csdnceshi52 妄徒之命 5年前

    To add package in dependencies:

    npm install my_dep --save
    

    or

    npm install my_dep -S
    

    To add package in devDependencies

    npm install my_test_framework --save-dev
    

    or

    npm install my_test_framework -D
    

    package.json enter image description here

    点赞 22 评论 复制链接分享
  • csdnceshi51 旧行李 3年前

    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 enter image description here

    点赞 10 评论 复制链接分享
  • weixin_41568208 北城已荒凉 3年前

    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.

    点赞 9 评论 复制链接分享
  • csdnceshi75 衫裤跑路 4年前

    npm install package_x --save

    The given package (package_x) will be saved in package.json inside dependencies. if you add

    npm install <> --save-dev

    then it will be saved inside "devDependencies".

    点赞 7 评论 复制链接分享
  • csdnceshi62 csdnceshi62 4年前

    As of npm 5, it is more favorable to use --save-prod (or -P) than --save but doing the same thing, as is stated in npm install. So far, --save still works if provided.

    点赞 5 评论 复制链接分享
  • weixin_41568174 from.. 4年前

    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
    -ddd: --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
    
    点赞 4 评论 复制链接分享
  • csdnceshi66 必承其重 | 欲带皇冠 4年前

    As of npm 5, npm will now save by default. In case,if you would like npm to work in a similar old fashion (no autosave) to how it was working in previous versions, you can update the config option to enable autosave as below.

    npm config set save false
    

    To get the current setting, you can execute the following command:

    npm config get save
    

    Source:https://blog.pusher.com/what-you-need-know-npm-5/

    点赞 4 评论 复制链接分享
  • weixin_41568126 乱世@小熊 3年前

    according to NPM Doc

    enter image description here

    So it seems that by running npm install package_name, the package dependency should be automatically added to package.json right?

    点赞 4 评论 复制链接分享

相关推荐