提交自己的包到bower、npm中

转载地址

bower

Bower 是 twitter 推出的一款包管理工具,基于nodejs的模块化思想,把功能分散到各个模块中,让模块和模块之间存在联系,通过 Bower 来管理模块间的这种联系。

bower官网

安装Bower

一旦你已经安装了上面所说的所有必要文件,键入以下命令安装Bower:

$ npm install -g bower

这行命令是Bower的全局安装,-g 操作表示全局。

使用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 卸载storejs

注册

添加配置文件

bower.json文件的使用可以让包的安装更容易,你可以在应用程序的根目录下创建一个名为 bower.json 的文件,并定义它的依赖关系。使用bower init 命令来创建bower.json文件:

$ bower init
? name: store.js
? version: 1.0.1
? description: "本地存储localstorage的封装,提供简单的AIP"
? authors: (kenny.wang )
? 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 )'
  ],
  description: '"本地存储localstorage的封装,提供简单的AIP"',
  moduleType: [
    'amd',
    'node'
  ],
  keywords: [
    'storejs'
  ],
  license: 'MIT',
  ignore: [
    '**/.*',
    'node_modules',
    'bower_components',
    'test',
    'tests'
  ]
}

? Looks good?: Yes

注册自己的包

可以注册自己的包,这样其他人也可以使用了,这个操作只是在服务器上保存了一个隐射,服务器本身不托管代码。

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  --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 )
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": "  (kenny.wang )",
  "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

据说已经不更新了,日后如果有研究再补充!

你可能感兴趣的:(提交自己的包到bower、npm中)