rails 3.0 压缩 javascript 和 css ( compress css/js in rails 3.0- )
访问量: 3564
压缩 javascript 和 css
参考 (refer to ): http://stackoverflow.com/questions/7112218/how-to-install-a-plugin-in-rails-3-getting-a-commands-is-not-a-module-typeerro/23507780#23507780
1. 编辑 Rakefile: (edit Rakefile)
require File.expand_path('../config/application', __FILE__)
require 'rake'
# 增加这一行,注意位置。 ( add this line of code)
include Rake::DSL
2.编辑: script/rails:
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
# 增加这一行,注意位置。 (add this line of code)
module Commands; end
require 'rails/commands'
3.then run this command:
$ bundle exec rails plugin install git://github.com/sbecker/asset_packager.git
4. 编辑: 新增一个 yml 文件, 把你用到的JS, CSS文件放到里面去: $ cat config/asset_packages.yml ( create a yml file as below)
--- javascripts: - base: - jquery-1.9.1.min - bootstrap.min - jquery-migrate-1.1.1 - jquery-ui-1.10.1.custom.min - jquery-ujs-for-jquery-1.9 - jquery.treeview - jquery.toastmessage - jquery.tooltip - jquery-autocomplete-combobox - jquery.uploadify - jquery-ui-timepicker-addon - jquery.ui.datepicker-zh-CN - select2 - select2_locale_zh-CN - global - jquery.tagit - jquery.validate - jqueryui-editable - jquery.ui.widget stylesheets: - base: - style - invalid - reset - jquery.treeview - jquery-ui-1.10.1.custom - jquery.toastmessage - jquery-autocomplete-combobox - uploadify - select2 - jquery.tagit - jquery.validate - cms - jqueryui-editable - bootstrap.min - customized_bootstrap
5. 在 布局文件(origin.html.erb)中: ( in your layout file)
<%= raw stylesheet_link_merged :base %> <%= raw javascript_include_merged :base %>
就可以了。 (done)
更多,见: (refer to ) https://github.com/sbecker/asset_packager