npm发包流程

yt-comment-date-format包为例:

npm常用命令

1
2
3
4
5
6
7
8
9
10
11
12
# 登录
npm login
# 查看当前用户
npm whoami
# 创建包
npm init packagename -y
# 查看本地当前使用的registry
npm config get registry
# 将npm源切换为https://registry.npmjs.org/
npm set registry https://registry.npmjs.org/
# 发布
npm publish

NPM镜像

查询

npm get registry

设官方

npm config set registry https://registry.npmjs.org/
设淘宝
npm config set registry https://registry.npm.taobao.org/

Yarn

查询

yarn config get registry

设官方

yarn config set registry https://registry.yarnpkg.com
设淘宝
yarn config set registry https://registry.npm.taobao.org/

使用babel将代码转es5

在根目录新建.babelrc文件中写入如下内容

1
2
3
4
5
6
{
"presets": [
"es2015"
],
"plugins": []
}

将代码转为es5

1
2
3
npm i -g babel-cli
npm i --save-dev babel-preset-es2015 babel-cli
babel index.es6.js -o index.js

同步淘宝镜像

如果使用了淘宝镜像,需要立即同步,有下面两种办法:

1
2
# 使用cnpm命令
cnpm sync yt-comment-date-format
1
2
# 打开链接
open https://npm.taobao.org/sync/yt-comment-date-format

npm发包流程
http://example.com/20200728-npm/
作者
csorz
发布于
2020年7月28日
许可协议