提交自己的包到 npm 中


npm

npm全稱Node Package Manager,是node.js的模塊依賴管理工具。使用github管理NPM包的代碼,並定期提交至NPM服務器;
npm官網

提交自己開發的NPM包

創建package.json文件

package.json文件的使用可以讓包的安裝更容易,你可以在應用程序的根目錄下創建一個名為 package.json 的文件,並定義它的依賴關系。使用npm init 命令來創建package.json文件:

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (store.js)
version: (1.0.0)
description: Local storage localstorage package provides a simple API
entry point: (store.js)
test command: store.js
git repository: (https://github.com/jaywcjlove/store.js.git)
keywords: store.js
author: (kenny.wang <wowohoo@qq.co>)
license: (ISC) MIT
About to write to /Applications/XAMPP/xamppfiles/htdocs/git/github.com/myJS/store.js/package.json:

{
  "name": "store.js",
  "version": "1.0.0",
  "description": "Local storage localstorage package provides a simple API",
  "main": "store.js",
  "scripts": {
    "test": "store.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/jaywcjlove/store.js.git"
  },
  "keywords": [
    "store.js"
  ],
  "author": " <wowohoo@qq.co> (kenny.wang <wowohoo@qq.co>)",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/jaywcjlove/store.js/issues"
  },
  "homepage": "https://github.com/jaywcjlove/store.js"
}


Is this ok? (yes) yes

發布到線上

添加用戶

按照提示輸入用戶名,密碼和郵箱

npm adduser

登陸用戶

按照提示輸入用戶名,密碼和郵箱

npm login

發布

npm publish

如果不帶參數,則會在當前目錄下查找package.json文件,按照該文件描述信息發布;
如果指定目錄,就會在指定目錄下查找package.json文件
測試是否發布成功,在官網搜索一下www.npmjs.com

注: package.json 中的name不要又特殊字符哦

版本更新

修改package.json里的版本號,重新npm publish

取消發布

npm unpublish

其它命令

npm install storejs 下載使用
npm config set registry https://registry.npm.taobao.org 更換鏡像地址
npm config get registry 獲取鏡像地址
npm dist-tag ls jslite 查看當前版本
npm dedupe 盡量壓平依賴樹


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM