初始化项目
- 新建目录并初始化
1 | mkdir publish-test |
- 修改
package.json
信息,如:
1 | { |
- 创建
index.js
文件
1 | console.log('publish-test', 'index.js') |
注册 npm 账号
前往官网注册账号: https://www.npmjs.com/
确保npm源为官方库
1 | npm config set registry https://registry.npmjs.org |
发布
- 执行发布命令
1 | npm publish |
- 打开个人页面查看发布信息
其他项目中安装
- 创建测试项目
1 | mkdir publish-test-install |
- 安装项目
1 | npm install --save-dev publish-test |
package.json
文件查看是否安装成功,并在scripts
下添加指令
1 | { |
- 创建
index.js
1 | require('publish-test') |
- 运行测试
1 | npm start |