Skip to content

@jsmestad /assets.yml
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rails 3.0.x runtime compilation and asset packaging with Barista and Jammit on Heroku
# config/assets.yml
package_assets: on
compress_assets: on
# compress_assets: off
javascript_compressor: uglifier
javascripts:
all:
- public/javascripts/jquery.min.js
- public/javascripts/jquery_ujs.js
- public/javascripts/jquery-ui.min.js
- public/javascripts/**/*.js
# pull in all the compiled javascripts (from barista)
- tmp/javascripts/**/*.js
stylesheets:
all:
# pull in all the compiled stylesheets (from compass/sass)
# - tmp/stylesheets/compiled/**/*.css
ie:
# - tmp/stylesheets/ie.css
# config/initializers/barista_config.rb
# Configure barista.
Barista.configure do |c|
# Change the root to use app/scripts
# c.root = Rails.root.join("app", "scripts")
c.root = Rails.root.join("app", "coffeescripts")
# Change the output root, causing Barista to compile into public/coffeescripts
# c.output_root = Rails.root.join("public", "coffeescripts")
c.output_root = Rails.root.join("tmp", "javascripts") # Heroku patch
# Disable auto compile, use generated file directly:
# c.auto_compile = false
# Add a new framework:
# c.register :tests, :root => Rails.root.join('test', 'coffeescript'), :output_prefix => 'test'
# Disable wrapping in a closure:
c.bare = true
# ... or ...
# c.bare!
# c.before_compilation { |path| puts "Barista: Compiling #{path}" }
# c.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }
# c.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }
# c.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }
# Make helpers and the HAML filter output coffee-script instead of the compiled JS.
# Used in combination with the coffeescript_interpreter_js helper in Rails.
# c.embedded_interpreter = true
end
# config/initializers/heroku_specifics.rb
require 'fileutils'
Rails.configuration.middleware.delete('Barista::Filter')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Barista::Filter')
if Rails.env.development?
class Jammit::Packager
alias_method :old_individual_urls, :individual_urls
def individual_urls(package, extension)
Rails.logger.info "[HEROKU] Rewriting /tmp/javascript paths to /javascript"
old_individual_urls(package, extension).collect { |c| c.gsub(/^\/tmp\//, '/') }
end
end
end
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/javascripts'],
:root => "#{Rails.root}/tmp")
@jsmestad
Owner

There is one hiccup that needs to be patched in Jammit. Currently, Jammit requires YUI regardless of specifying the use of "uglifier" in the assets. This dependency check is there because Jammit currently only supports YUI compression for CSS. There is an open issue for fixing, or disabling, this: documentcloud/jammit#162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.