自行下載並安裝node
pkgtest
目錄,進入該目錄,建立pkgtest.js
文件,文件內容以下:function pkgtestpkg(param) { console.log('param is: ',param); } exports.pkgtestpkg = pkgtestpkg;
package.json
文件,pkgtest目錄下執行npm init
,按提示輸入指定的內容便可,例如:package name: (pkgtestpkg) version: (1.0.0) description: first pkg test entry point: (pkgtest.js) test command: git repository: https://github.com/your-github-account/pkgtestpkg.git keywords: pkg test author: npm_user_name //這裏要事先在npm官網註冊帳號 license: (ISC) ISC
發佈包以前必須事先註冊一個npm帳號,去官網 https://www.npmjs.com/ 自行註冊。git
npm adduser // 輸入本身的npm帳號、密碼、郵箱
npm login // 輸入帳號、密碼、郵箱,登陸後方可發包
npm publish
npm unpublish [--force] // 不成功能夠強制取消
登陸官網 https://www.npmjs.com/ ,便可看到剛纔發佈的包,若是網不是很好,可能等一會才能看到。github
進入任意目錄下,執行npm init
建立package文件,執行npm i pkgtestpkg
,執行完後,在任意js文件中加載剛纔安裝的pkgtestpkg
包。例如:npm
let pkgtestpkg = require('pkgtestpkg'); console.log(pkgtestpkg.pkgtestpkg());
git remote add origin git@server-name:path/reponame.git // 關聯到遠程倉庫 git push // 推送上去