npm

打开用户目录下的.npmrc文件即可查看配置
node_modules扁平化原则,不管是直接依赖还是子依赖都优先放置到node_modules根目录
缓存机制

npm 脚本参数获取

  1. "scripts": {
  2. "start": "node echoargs.js $*"
  3. }
  1. console.log('arguments: ' + process.argv.slice[2]);
  1. npm start 1 2 3
  2. arguments: 1,2,3
  1. npm config list # 查看npm的配置
  2. npm config ls -l # 查看npm的详细配置
  3. npm config get prefix # 查看npm包全局安装位置
  4. npm config set prefix 'PATH' # 设置npm包的全局安装位置
  5. npm config get cache # 查看npm包全局缓存位置
  6. npm config set cache 'PATH' # 设置npm包缓存位置
  7. 1.npm地址
  8. npm config set registry http://registry.npmjs.org
  9. 2.设置国内镜像
  10. a.通过config命令
  11. npm config set registry https://registry.npm.taobao.org
  12. npm info underscore (如果上面配置正确这个命令会有字符串response
  13. b.命令行指定
  14. npm --registry https://registry.npm.taobao.org info underscore
  15. c.编辑~/.npmrc加入下面内容
  16. registry = https://registry.npm.taobao.org
  17. 3.使用nrm管理registry地址
  18. a.下载nrm
  19. npm install -g nrm
  20. b.添加registry地址
  21. nrm add npm http://registry.npmjs.org
  22. nrm add taobao https://registry.npm.taobao.org
  23. c.切换npm registry地址
  24. nrm use taobao
  25. nrm use npm
  26. 查看源地址:npm config get registry
  27. 设置源地址:npm config set registry https://registry.npm.taobao.org/
  28. npm官方源地址:https://registry.npmjs.org
  29. 淘宝镜像源地址:https://registry.npm.taobao.org/
  30. nrm ls
  31. npm -------- https://registry.npmjs.org/
  32. yarn ------- https://registry.yarnpkg.com/
  33. cnpm ------- http://r.cnpmjs.org/
  34. * taobao ----- https://registry.npm.taobao.org/
  35. nj --------- https://registry.nodejitsu.com/
  36. npmMirror -- https://skimdb.npmjs.com/registry/
  37. edunpm ----- http://registry.enpmjs.org/
  38. 有些内网限制,安装nodejs时,不会注册node_modules路径到全局环境变量,所以我们需要手动配置环境变量
  39. npm config get prefix
  40. 获取npm全局安装路径
  41. 然后手动添加到环境变量里面
  42. 安装yarn
  43. npm install -g yarn
  44. yarn --version
  45. yarn config set network-timeout 600000 -g

yarn

打开用户目录下的.yarnrc文件即可查看配置

  1. yarn -v # 查看版本
  2. yarn config list # 查看yarn配置
  3. yarn global dir # 查看全局安装位置 C:\Users\xiao\AppData\Local\Yarn\Data\global
  4. yarn global bin # 查看当前yarn的bin的位置
  5. yarn cache dir # 查看yarn的全局缓存目录 C:\Users\xiao\AppData\Local\Yarn\Cache\v6
  6. yarn cache list # 查看缓存资源列表
  7. # 修改yarn的源镜像为淘宝源
  8. yarn config set registry https://registry.npm.taobao.org/
  9. # 默认源是 https://registry.yarnpkg.com
  10. # 修改全局安装目录
  11. yarn config set global-folder "PATH" # D:\apptools\yarn\global-data
  12. # 修改全局缓存目录
  13. yarn config set cache-folder "PATH"
  14. # 修改全局安装目录的bin目录位置
  15. yarn config set prefix "PATH" # 需要配置环境变量
  16. # 下载、更新、删除依赖包
  17. yarn add添加一个包 相当 npm install [packageName] --save
  18. yarn add [package] --dev 相当 npm install [package] --save-dev
  19. yarn add [package]@[version] # 安装指定版本
  20. yarn upgrade更新一个包 相当 npm update webpack
  21. yarn remve移除本地依赖包 相当 npm uninstall [package]
  22. # 切换为淘宝镜像源
  23. yarn config set registry https://registry.npm.taobao.org
  24. yarn config set sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
  25. yarn config set phantomjs_cdnurl "http://cnpmjs.org/downloads"
  26. yarn config set electron_mirror "https://npm.taobao.org/mirrors/electron/"
  27. yarn config set sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"
  28. yarn config set profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"
  29. yarn config set chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"