在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/