npm宣布包
初始化
在https://www.npmjs.com/這裏註冊登錄,
起一個名字,比方http-auth-zfb,起首查詢是不是已存在
mkdir http-auth-zfb
cd http-auth-zfb
npm init -y
新建進口文件 index.js
//index.js
module.exports = require('./lib/index');
要宣布的文件放到lib文件夾下
宣布
npm login
登錄會填寫你在npmjs.com
註冊的用戶名暗碼郵箱等信息。
npm login
npm publish
更新宣布
只須要變動版本號然後npm publish
假如宣布的有es6代碼
新建src
目次,把原始文件(es6代碼),放入src
,須要babael
轉化
"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
毛病
npm ERR! publish Failed PUT 401
處理歷程:
- 搜檢堆棧是不是被設成了淘寶鏡像庫
npm config get registry
- 如是,則設回原堆棧
npm config set registry=http://registry.npmjs.org
- 登錄賬號(如未登錄)
npm login
或許增加用戶 npm adduser
- 再次宣布
npm publish
- 如宣布勝利,則再次將堆棧地點設為淘寶鏡像地點
npm config set registry=https://registry.npm.taobao.org/