Skip to content

Instantly share code, notes, and snippets.

@lg
Created March 8, 2013 23:21
Show Gist options
  • Select an option

  • Save lg/5120914 to your computer and use it in GitHub Desktop.

Select an option

Save lg/5120914 to your computer and use it in GitHub Desktop.
Force files to be precompiled by the Rails 3 asset pipeline via instructions in _precompile.js and _precompile.css. Add this to config/environments/production.rb
get_requires_from_file = Proc.new do |filename|
files = Sprockets::DirectiveProcessor.new(filename).directives.collect { |f| f[1] == "require" ? f[2] : nil }.compact
files.collect do |file|
search_path = File.join(File.dirname(filename), file)
files = Dir.glob("#{search_path}.*")
files.collect { |f| File.basename(f) }
end.flatten
end
config.assets.precompile +=
get_requires_from_file.call("app/assets/javascripts/_precompile.js") +
get_requires_from_file.call("app/assets/stylesheets/_precompile.css")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment