希曼日记

npm指令

NPM指令

#PackageManage #命令

卸载

Shell
npm uninstall --save-dev
npm uninstall -g
npm uninstall

强制重新build,重新构建package依赖

Shell
npm rebuild

清除缓存

Shell
npm cache clean

查看.npmrc位置

Shell
npm config list

编辑.npmrc文件

Shell
npm config edit

查看npm版本

Shell
npm -v

获取npm配置缓存位置

Shell
npm config get cache

检查当前npm源 切换回npm默认源

Shell
npm get registry

切换到npm淘宝源(淘宝源亲测不是总是最新的)

Shell
npm config set registryhttps://registry.npm.taobao.org/

切换回npm默认源

Shell
npm config set registryhttps://registry.npmjs.org

npm 与 yarn 对比

Text
+--------------------------------------------------+--------------------------+
| npm | yarn |
+==================================================+==========================+
| npm install | yarn install |
+--------------------------------------------------+--------------------------+
| npm install <package> | yarn add <package> |
+--------------------------------------------------+--------------------------+
| npm install <package> --save | yarn add <package> |
| npm install <package> --save-dev | yarn add <package> --dev |
+--------------------------------------------------+--------------------------+
| npm uninstall <package> | yarn remove <package> |
| npm uninstall <package> --save-dev | yarn remove <package> |
| npm uninstall <package> -save-optional [package] | yarn remove <package> |
+--------------------------------------------------+--------------------------+
| 清除缓存 | npm cache clean |
| npm cache clean | |
+--------------------------------------------------+--------------------------+
| 卸载node_module并重新安装 | yarn upgrade |
| rm -rf node_modules && npm install | |
+--------------------------------------------------+--------------------------+