首页 > 代码库 > 如何建立一个bower私库

如何建立一个bower私库

本教程适用于centos

安装之前

检查nodejs

如果没安装nodejs按照以下步骤安装

$ su - 
$ yum install openssl-devel
$ cd /usr/local/src
$ wget http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz
$ tar zxvf node-v0.10.29.tar.gz
$ cd node-v0.10.29
$ ./configure
$ make
$ make install

查一下版本号,看有没有安装成功:  
$ node -v
v0.10.29


检查git

如果没安装,请按照以下步骤安装

$ sudo yum -y install git

开始安装bower私库

STEP 1 安装 git 和 git-deamon

$ sudo yum install -y git git-daemon

STEP 2 安装 private-bower

$ sudo npm install -g private-bower

STEP 3 设置 private-bower 

$ sudo su -
$ cd /data
$ mkdir private-bower
$ vim /data/private-bower-config.json


将以下内容粘贴进去:
{
    "port": 5678,
    "registryFile": "./private-bower/bowerRepository.json",
    "disablePublic": false,
    "publicRegistry": "http://bower.herokuapp.com/packages/",
    "repositoryCache": {
        "git": {
            "enabled": true,
            "cacheDirectory": "./private-bower/gitRepoCache",
            "host": "localhost",
            "port": 6789
        },
        "svn": {
            "enabled": true,
            "cacheDirectory": "./private-bower/svnRepoCache",
            "host": "localhost",
            "port": 7891
        }
    },
    "log4js" : {
        "enabled": true,
        "configPath" : "./private-bower/log4js.conf.json"
    }
}

$ vim /data/private-bower/log4js.conf.json

{
    "appenders": [
        {
            "type": "dateFile",
            "filename": "./private-bower/private-bower.log",
            "pattern": "-yyyy-MM-dd",
            "alwaysIncludePattern": false
        },
        {
            "type": "console"
        }
    ],
    "replaceConsole": true
}


启动 private-bower
$ sudo su -
$ cd /data
$ private-bower --config ./private-bower-config.json
[2014-06-30 10:00:22.481] [INFO] console - [bower]  Refreshing public packages...
[2014-06-30 10:00:22.512] [INFO] console - [bower]  Bower server started on port 5678
[2014-06-30 10:00:22.538] [INFO] console - [bower]  Starting git cache server
[2014-06-30 10:00:22.543] [INFO] console - [bower]  Starting svn cache server
[2014-06-30 10:01:09.167] [INFO] console - [bower]  Loaded public packages




确保 private-bower 正常启动:
打开一个新窗口来访问:
$ lynx http://localhost:5678/

会显示:
   
   Fork me on GitHub


Private Bower


   ____________________
   Docs Public Packages
   Private Bower service is down
   No private packages registered read docs about how to register packages.
   Loading Packages...


{{ package.name }}


   hits: {{ package.hits }}
   {{ package.repo }}


Created by


   BarnaToth


Barna Tóth


如果是这样,就安装完毕了




客户端测试

$ sudo su -
$ npm install -g bower
$ su - wlsuser
$ bower help
$ vim .bowerrc
{ "registry": "http://<your private repository ip>:5678" }
$ cd <testdir>
$ bower install jquery