学习
-
- nrm 管理指的是 ‘npm’ 的镜像源管理工具
-
- 上传npm包
- a. npm常用操作
- b. 上传npm包
- c. 生成一个包
- 上传npm包
-
- yarn的使用
nrm 软件
nrm是专门用来管理和快速切换私人配置的registry
建议全局安装
npm install nrm -g --save
用nrm ls命令查看默认配置,带*号即为当前使用的配置
nrm ls
npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/
也可以直接输入以下命令查看当前使用的是哪个源 [也可以直接输入以下命令查看当前使用的是哪个源]
nrm current
切换源
nrm use cnpm
用nrm add 命令添加公司私有npm源,如registry.npm.360.org(随便写的)
起别名叫qihoo
nrm add qihoo http://registry.npm.360.org
npm常用操作
(1)npm查看当前源:
npm get registry [npm 获取注册表]
(2)npm设置淘宝镜像源:
npm config set registry registry.npm.taobao.org
(3)npm设置官方源:
npm config set registry www.npmjs.org
上传包
- 设置仓库地址
npm get registry [npm 获取注册表]
2登录账号(如未登录)
npm login
3再次发布
npm publish
包的生成
npm init
初始化包
package.json
{
"name": "@rc-hook",
"version": "1.0.0",
"description": "edit hook",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"hook"
],
"author": "handsomeguy.he",
"license": "ISC"
}
index.js
module.exports = {
a: (a, b) => { return a + b}
}
添加bin使用
{
"name": "@rc-hook",
"version": "1.0.0",
"description": "edit hook",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"hook"
],
"author": "handsomeguy.he",
"license": "ISC"
}
"bin": {
"q-cli": "./bin/index.js"
}
}
yarn
在项目开发中,有时需要使用私有npm库,这是就需要去切换源
- 方法一
在项目的根目录添加.npmrc文件;
**
// .npmrc 文件内容,地址可设置为源地址
registry='https://registry.npm.taobao.org/'
复制代码
注: 用内网时,切换外网yarn时,需要把yarn.log删掉
- 方法二
全局设置源地址,只想在当前项目生效,则去掉 --global
**
// 查看当前源
yarn config get registry
// 设置淘宝或内网源
yarn config set registry https://registry.npm.taobao.org --global
// 恢复源
yarn config set registry https://registry.yarnpkg.com --global
复制代码
登录
**
yarn login