assets.rake 1.1 KB
Newer Older
1
namespace :assets do
2
  desc "Compile all the assets named in config.assets.precompile"
3 4 5
  task :precompile do
    # We need to do this dance because RAILS_GROUPS is used
    # too early in the boot process and changing here is already too late.
6 7 8
    if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
      ENV["RAILS_GROUPS"] ||= "assets"
      ENV["RAILS_ENV"]    ||= "production"
9 10 11
      Kernel.exec $0, *ARGV
    else
      Rake::Task["environment"].invoke
J
Jon Leighton 已提交
12 13 14

      # Ensure that action view is loaded and the appropriate sprockets hooks get executed
      ActionView::Base
15

16 17 18 19 20
      assets = Rails.application.config.assets.precompile
      # Always perform caching so that asset_path appends the timestamps to file references.
      Rails.application.config.action_controller.perform_caching = true
      Rails.application.assets.precompile(*assets)
    end
21
  end
22 23

  desc "Remove compiled assets"
24
  task :clean => [:environment, 'tmp:cache:clear'] do
25 26
    assets = Rails.application.config.assets
    public_asset_path = Rails.public_path + assets.prefix
27
    rm_rf public_asset_path, :secure => true
28
  end
29
end