Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 4, 2012 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoran/4200226 to your computer and use it in GitHub Desktop.
Save jrmoran/4200226 to your computer and use it in GitHub Desktop.
Sprockets 2.8.1 Precompile CoffeeScript for non rack apps
namespace :js do
require 'sprockets'
environment = Sprockets::Environment.new(File.dirname(__FILE__))
environment.append_path 'src/bower'
environment.append_path 'src/coffee'
source_code = environment['app.coffee']
desc 'compile CoffeeScript with Sprockets'
task :compile do
bundle_file = './build/js/app.bundle.js'
File.open(bundle_file, 'w'){ |f| f.write(source_code) }
puts "app.coffee -> #{bundle_file}"
end
desc 'compile and minify CoffeeScript with Sprockets'
task :min do
require 'uglifier'
bundle_min = './dist/js/app.bundle.min.js'
source_min = Uglifier.compile(source_code)
File.open(bundle_min, 'w'){ |f| f.write(source_min) }
puts "app.coffee -> #{bundle_min}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment