提交本身的包到bower、npm中

轉載地址node

bower

Bower 是 twitter 推出的一款包管理工具,基於nodejs的模塊化思想,把功能分散到各個模塊中,讓模塊和模塊之間存在聯繫,經過 Bower 來管理模塊間的這種聯繫。jquery

bower官網git

安裝Bower

一旦你已經安裝了上面所說的全部必要文件,鍵入如下命令安裝Bower:github

$ npm install -g bower

這行命令是Bower的全局安裝,-g 操做表示全局。express

使用bower

  1. 直接下載 git 庫: bower install git://github.com/JSLite/JSLite.git
  2. github別名自動解析git庫: bower install JSLite/JSLite
  3. 下載線上的任意文件: bower install http://foo.com/jquery.awesome-plugin.js
  4. 下載本地庫: bower install ./repos/jquery

經常使用命令

$ bower install jquery --save 添加依賴並更新bower.json文件
$ bower cache clean 安裝失敗清除緩存
$ bower install storejs 安裝storejs
$ bower uninstall storejs 卸載storejsnpm

註冊

添加配置文件

bower.json文件的使用可讓包的安裝更容易,你能夠在應用程序的根目錄下建立一個名爲 bower.json 的文件,並定義它的依賴關係。使用bower init 命令來建立bower.json文件:json

$ bower init
? name: store.js
? version: 1.0.1
? description: "本地存儲localstorage的封裝,提供簡單的AIP"
? authors: (kenny.wang <wowohoo@qq.co>)
? license: MIT
? homepage:
? set currently installed components as dependencies?: Yes
? add commonly ignored files to ignore list?: Yes
? would you like to mark this package as private which prevents it from being accidentally publis? would you like to mark this package as private which prevents it from being accidentally published to the registry?: No

{
  name: 'store.js',
  main: 'store.js',
  version: '1.0.1',
  authors: [
    '(kenny.wang <wowohoo@qq.co>)'
  ],
  description: '"本地存儲localstorage的封裝,提供簡單的AIP"',
  moduleType: [
    'amd',
    'node'
  ],
  keywords: [
    'storejs'
  ],
  license: 'MIT',
  ignore: [
    '**/.*',
    'node_modules',
    'bower_components',
    'test',
    'tests'
  ]
}

? Looks good?: Yes

註冊本身的包

能夠註冊本身的包,這樣其餘人也可使用了,這個操做只是在服務器上保存了一個隱射,服務器自己不託管代碼。segmentfault

bower register storejs git://github.com/jaywcjlove/store.js.git

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 adduser

發佈

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 儘可能壓平依賴樹

國內優秀npm鏡像

因爲npm的源在國外,因此國內用戶使用起來各類不方便。
利用kappa搭建私有NPM倉庫

淘寶npm鏡像

  1. 搜索地址:http://npm.taobao.org/
  2. registry地址:http://registry.npm.taobao.org/

cnpmjs鏡像

  1. 搜索地址:http://cnpmjs.org/
  2. registry地址:http://r.cnpmjs.org/

臨時使用

npm --registry https://registry.npm.taobao.org install express

持久使用

npm config set registry https://registry.npm.taobao.org
// 配置後可經過下面方式來驗證是否成功
npm config get registry
// 或
npm info express

經過cnpm使用

npm install -g cnpm --registry=https://registry.npm.taobao.org

// 使用
cnpm install expresstall express

spmjs

spmjs

聽說已經不更新了,往後若是有研究再補充!

相關文章
相關標籤/搜索