提交本身的包到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

听说已经不更新了,往后若是有研究再补充!

相关文章
相关标签/搜索