1.npm
1.1 安装
安装node后自带了npm
2.2 初始化package.json
npm init
1.3 安装包
单个包:npm install less或npm i less
 所有包:npm install````npm i
1.4 删除包
npm remove less,npm r less或npm uninstall less
1.5 配置别名
package.json中:
{"name": "test","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1","dev":"node index.js",//npm run dev启动"start":"nodemon index.js"//npm start 启动},"author": "xx","license": "ISC"
}
1.6 npm配置淘宝镜像
npm config set registry https://registry.npm.taobao.org/
 设置官方镜像:
 npm config set registry https://registry.npmjs.org
1.7 npm 发布一个包
创建包:
- 创建文件夹,并创建文件index.js,在文件中声明函数,使用module.exports暴露
- npm初始化工具包(npm init)package.json填写包信息
- 注册账号https://www.npmjs/com/signup
- 激活账号
- 修改为官方镜像源
- 命令行下npm login填写用户相关信息
- 命令行下npm publish提交包
更新包:
- 更新包中代码
- 测试代码可用性
- 修改package.json中的版本号
- 发布 npm publish
删除包:
- 命令:npm unpublish
- 满足条件: - 你是包作者
- 发布大于24h
- 大于24h后,没有其他包依赖,并且每周小于300下载量,并且只有一个维护者
 
2.yarn
2.1 安装
npm i -g yarn
2.2 初始化package.json
yarn init
2.3 安装包
单个包:yarn add less
 所有包:yarn
2.4 删除包
yarn remove less
2.5 配置别名
package.json中:
{"name": "test","version": "1.0.0","description": "hh","main": "index.js","scripts":{"start":"nodemon index.js" //yarn start可启动},"license": "MIT"
}
2.6 yarn配置淘宝镜像
yarn config set registry https://registry.npmirror.com/