在https://www.npmjs.com/这里注册登陆,
起一个名字,好比http-auth-zfb,首先查询是否已存在es6
mkdir http-auth-zfb cd http-auth-zfb npm init -y
//index.js module.exports = require('./lib/index');
要发布的文件放到lib文件夹下npm
npm login
登陆会填写你在npmjs.com
注册的用户名密码邮箱等信息。json
npm login npm publish
只须要更改版本号而后npm publish
bash
新建src
目录,把原始文件(es6代码),放入src
,须要babael
转化babel
"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "babel src --out-dir lib" }, "devDependencies": { "babel-cli": "^6.26.0", "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-3": "^6.24.1" }, "dependencies": { "transform-runtime": "^0.0.0" }
发布前,执行npm run build
转化后的代码会在lib下面,更改版本号,在执行npm publish
ui
npm ERR! publish Failed PUT 401
解决过程:code
npm config get registry
orm
npm config set registry=http://registry.npmjs.org
ip
npm login
或者添加用户 npm adduser
ci
npm publish
npm config set registry=https://registry.npm.taobao.org/