提醒:
注:不推荐使用cnpm,一些依赖会出现bug。 推荐使用npm和yarn。
npm淘宝镜像
npm 使用淘宝镜像时速度比yarn快。
将npm设置为淘宝镜像:
npm config set registry https://registry.npm.taobao.org
查看npm镜像地址:
npm config get registry
淘宝镜像卸载
npm config set disturl https://npm.taobao.org/dist
命令
/ | npm | yarn |
安装 | nodejs自带 | npm install -g yarn |
初始化项目 | npm init | yarn init |
安装依赖 | npm install / i | yarn install |
移除某个依赖 | npm uninstall jquery | yarn remove jquery |
安装全局依赖 | npm i jquery -g | yarn global add jquery |
安装开发依赖 | npm i jquery -dev | yarn add jquery --dev |
安装生产依赖 | npm i jquery --save | yarn add jquery --save |
运行某个名称假设是serve | npm run [serve] | yarn [serve] |
发布/登录/登出,npm网站操作 | npm publish/login/logout | yarn publish/login/logout |
更新模块 | npm update jquery@3.0.0 | yarn upgrade jquery@3.0.0 |
当前版本 | npm -v | yarn -v |
包储存位置的根目录 | npm root | |
全局的包的安装路径 | npm root -g | |
查看安装模块(加-g是全局的) | npm list | |
只查看一级的 | npm list -g --depth 0 | |
清理缓存数据 | npm cache clean --force(有点问题) |
一些特殊命令符号
--save 相当于 -S 加载在package.json的dependencies里面(生产依赖)
--dev 相当于 -D 加载在package.json的devDependencies里面(开发依赖,比如less等,在正式环境不需要)
@3.0.0 表示某个模块的3.0.0这个版本