【NodeJs环境下bower】如何更改bower_components文件夹的位置?

bower在初始化,默认是将bower_components文件夹放到项目的根目录下,若是public/index.html如何配置bower_components下的js或者css类库呢?只需要将bower_components配置为项目的静态目录,

APP.js文件内容增加内容:

  app.use(express.static(__dirname+'/bower_components'));

根据项目的需要有时候,我们不想把bower_components文件夹放到项目的根目录下,假设我们想把bower_components文件夹放到public下面,具体操作见下面步骤:

  1. 创建Bower配置文件【.bowerrc】,这个文件是作为bower的配置文件,默认情况的话,可以不存在,若是更改bower_components位置需要更改此文件中的内容。
mkdir public/bower_components
vim .bowerrc

.bowerrc文件内容如下:

{
"directory":"public/bower_components"
}

2、安装bootstrap,angular,若是采用root用户,则需要使用--allow-root

bower install --save --allow-root angular
bower install --save --allow-root bootstrap