Skip to content

Latest commit

 

History

History
95 lines (62 loc) · 2.14 KB

npm.md

File metadata and controls

95 lines (62 loc) · 2.14 KB

npm

命令

  • npm init

    • npm init -y 跳过向导 快速生成
  • npm install

  • npm install 包名

    • 只下载
    • npm i
  • npm install --save 包名

    • 下载并保存依赖项

    • npm i -S 包名

  • npm i xx --save-exact
    • 安装一个第三方包,将一个确定的依赖版本写死在package.json中
  • npm uninstall 包名
    • 只删除,如果有依赖项会依然保存
    • npm un 包名
  • npm uninstall --save 包名
    • 删除的同时去除依赖信息
    • npm un -S 包名
  • npm help
    • 查看使用帮助
  • npm 命令 -help
    • 查看指定命令的使用帮助

清除npm缓存

npm cache clean --force

npm淘宝镜像地址

https://registry.npmmirror.com

npm config set registry https://registry.npmmirror.com
yarn config set registry https://registry.npmmirror.com

切回原镜像

npm config set registry https://registry.npmjs.org

node-sass淘宝镜像地址

https://npmmirror.com/mirrors/node-sass/ 

npm config set sass_binary_site=https://npmmirror.com/mirrors/node-sass/ 
yarn config set sass_binary_site=https://npmmirror.com/mirrors/node-sass/ 

JS读取当前运行的脚本名称

由npm提供的变量,返回当前所运行脚本的名称,如build等(via npm scripts 使用指南 - 阮一峰的网络日志 (ruanyifeng.com)

const TARGET = process.env.npm_lifecycle_event;

node与node-sass版本对应关系

node-sass - npm (npmjs.com)

.npmrc

registry=https://registry.npmmirror.com #指定特定的 registry 来获取依赖