npm
打开用户目录下的.npmrc文件即可查看配置
node_modules扁平化原则,不管是直接依赖还是子依赖都优先放置到node_modules根目录
缓存机制
npm 脚本参数获取
"scripts": {"start": "node echoargs.js $*"}
console.log('arguments: ' + process.argv.slice[2]);
npm start 1 2 3arguments: 1,2,3
npm config list # 查看npm的配置npm config ls -l # 查看npm的详细配置npm config get prefix # 查看npm包全局安装位置npm config set prefix 'PATH' # 设置npm包的全局安装位置npm config get cache # 查看npm包全局缓存位置npm config set cache 'PATH' # 设置npm包缓存位置1.原npm地址npm config set registry http://registry.npmjs.org2.设置国内镜像a.通过config命令npm config set registry https://registry.npm.taobao.orgnpm info underscore (如果上面配置正确这个命令会有字符串response)b.命令行指定npm --registry https://registry.npm.taobao.org info underscorec.编辑~/.npmrc加入下面内容registry = https://registry.npm.taobao.org3.使用nrm管理registry地址a.下载nrmnpm install -g nrmb.添加registry地址nrm add npm http://registry.npmjs.orgnrm add taobao https://registry.npm.taobao.orgc.切换npm registry地址nrm use taobaonrm use npm查看源地址:npm config get registry设置源地址:npm config set registry https://registry.npm.taobao.org/npm官方源地址:https://registry.npmjs.org淘宝镜像源地址:https://registry.npm.taobao.org/nrm lsnpm -------- https://registry.npmjs.org/yarn ------- https://registry.yarnpkg.com/cnpm ------- http://r.cnpmjs.org/* taobao ----- https://registry.npm.taobao.org/nj --------- https://registry.nodejitsu.com/npmMirror -- https://skimdb.npmjs.com/registry/edunpm ----- http://registry.enpmjs.org/有些内网限制,安装nodejs时,不会注册node_modules路径到全局环境变量,所以我们需要手动配置环境变量npm config get prefix获取npm全局安装路径然后手动添加到环境变量里面安装yarnnpm install -g yarnyarn --versionyarn config set network-timeout 600000 -g
yarn
打开用户目录下的.yarnrc文件即可查看配置
yarn -v # 查看版本yarn config list # 查看yarn配置yarn global dir # 查看全局安装位置 C:\Users\xiao\AppData\Local\Yarn\Data\globalyarn global bin # 查看当前yarn的bin的位置yarn cache dir # 查看yarn的全局缓存目录 C:\Users\xiao\AppData\Local\Yarn\Cache\v6yarn cache list # 查看缓存资源列表# 修改yarn的源镜像为淘宝源yarn config set registry https://registry.npm.taobao.org/# 默认源是 https://registry.yarnpkg.com# 修改全局安装目录yarn config set global-folder "PATH" # D:\apptools\yarn\global-data# 修改全局缓存目录yarn config set cache-folder "PATH"# 修改全局安装目录的bin目录位置yarn config set prefix "PATH" # 需要配置环境变量# 下载、更新、删除依赖包yarn add添加一个包 相当 npm install [packageName] --saveyarn add [package] --dev 相当 npm install [package] --save-devyarn add [package]@[version] # 安装指定版本yarn upgrade更新一个包 相当 npm update webpackyarn remve移除本地依赖包 相当 npm uninstall [package]# 切换为淘宝镜像源yarn config set registry https://registry.npm.taobao.orgyarn config set sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"yarn config set phantomjs_cdnurl "http://cnpmjs.org/downloads"yarn config set electron_mirror "https://npm.taobao.org/mirrors/electron/"yarn config set sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"yarn config set profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"yarn config set chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
