npm常用命令

2018-04-03  本文已影响8人  滚石_c2a6
  1. npm init [-f|--force|-y|--yes]
    This will ask you a bunch of questions, and then write a package.json for you.
    If you invoke it with -f, --force, -y, or --yes, it will use only defaults and not prompt you for any options.

2.npm install
Install the dependencies in the local node_modules folder.
By default, npm install will install all modules listed as dependencies in package.json

-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.
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.

3.npm ls
参数:
global
List packages in the global install prefix instead of in the current project.
depth
Max display depth of the dependency tree.
prod
Display only the dependency tree for packages in dependencies.
dev
Display only the dependency tree for packages in devDependencies.
示例;npm ls --depth=0 -g

4.npm uninstall
npm uninstall [<@scope>/]<pkg>[@<version>]... [-S|--save|-D|--save-dev|-O|--save-optional|--no-save]
aliases: remove, rm, r, un, unlink

--no-save: Package will not be removed from your package.json file.

5.npm update [-g] [<pkg>...]
aliases: up, upgrade

6.npm cache clean [<path>]
aliases: npm cache clear, npm cache rm
7.npm config
npm config list
npm config set <key> <value> [-g|--global]
npm config get <key>

修改源地址为淘宝 NPM 镜像:
npm config set registry http://registry.npm.taobao.org/
修改源地址为官方源:
npm config set registry https://registry.npmjs.org/

上一篇下一篇

猜你喜欢

热点阅读