bower-rails 配置与capistrano3整合
说索
项目大了,载入js开源的插件越来越多,碰到了:
- 1. 没有打成rails包 (难道要把js都打开gem包)
- 2. 都放在assets/javascripts (没有gem包,难道都要放在这下面,太多了!)
- 3. 不易与作者同步维护
bower 是一个不错的前端类库管理的工具,感觉像ruby中的bundler一样!赞!
bower-rails这个gem就是方便把rails与js管理拉近距离了!
ubuntu的bower环境安装
sudo apt-get install nodejs
sudo apt-get install npm
sudo npm install -g bower
bower-rails 安装
gem "bower-rails", "~> 0.9.2"
bundle install
rails g bower_rails:initialize
bower-rails 配置
vi Bowerfile
# A sample Bowerfile
# Check out https://github.com/42dev/bower-rails#ruby-dsl-configuration for more options
# asset 'bootstrap'
asset "timepicker", "1.3.2", git: "https://github.com/wvega/timepicker.git"
# 配置完Bowerfile
rake bower:install
bower:install完会发现vendor/assets下会多了这些多东西
$ tree vendor/assets
vendor/assets
├── bower.json
├── bower_components
│ └── timepicker
│ ├── AUTHORS
│ ├── CHANGELOG
│ ├── Gruntfile.js
│ ├── LICENSE-GPL
│ ├── LICENSE-MIT
│ ├── Makefile
│ ├── README.md
│ ├── jquery-timepicker.jquery.json
│ ├── jquery.timepicker.css
│ ├── jquery.timepicker.js
│ ├── package.json
... ...
capistrano3的配置
把这个加入config/deploy.rb中
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/cache public/system public/assets vendor/assets/bower_components}
#注: vendor/assets/bower_components 这里不要忘了
desc "bower_rails install"
namespace :bower_rails do
task :install do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env) do
execute :rake, "bower:install"
end
end
end
end
end
before 'deploy:assets:precompile', 'bower_rails:install'
cap production deploy