npm外掛-建立一個自己的npm
阿新 • • 發佈:2018-12-20
一個簡單npm外掛的開發步驟如下
1 找個資料夾,命令列裡輸入:
mkdir i8n-autoinsert
cd i18n-autoinsert
npm init
npm init會要求填寫一堆的資訊,這些資訊會在package.json裡體現,例如
{
"name": "i18n-autoinsert", //外掛名,在https://www.npmjs.com裡沒有的
"version": "1.0.6", //版本號,每次npm publish 要改下這個版本號
"description": "it is quit trouble when dev ux need supportmultiple language ,need to write tranlation key in en.json and html ,this plugin is to resolve this problem.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"commander": "^2.11.0"
},
"bin":{
"i18n-autoinsert":"./index.js"
},
"author": "rechard",
"license": "ISC"
}
2 index.js
在i18n-autoinsert專案裡建立一個index.js
index.js
#!/usr/bin/env node
console.info('hello world');
3 執行
node index.js
看到控制檯輸出
hello world
目錄i18n-autoinsert裡就只有如下
- node_modules
- index.js
- package.json
4 釋出
到https://www.npmjs.com註冊一個賬號,註冊完後
新增使用者
npm adduser
釋出自己的外掛到https://www.npmjs.com
npm publish
5 使用
npm install -save-dev i18n-autoinsert
