Skip to content

Instantly share code, notes, and snippets.

@LBRapid
Last active December 19, 2015 07:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LBRapid/5918253 to your computer and use it in GitHub Desktop.
Save LBRapid/5918253 to your computer and use it in GitHub Desktop.
Precompile javascript assets in a rails engine
namespace :assets do
ROOT = Pathname.new(File.dirname(__FILE__))
LOGGER = Logger.new(STDOUT)
APP_ASSETS_DIR = ROOT.join("app/assets")
PUBLIC_ASSETS_DIR = ROOT.join("vendor/assets")
OUTPUT_DIR = ROOT.join("public")
desc 'Compile assets'
task :compile => :compile_js
desc 'Compile javascript'
task :compile_js do
outfile = Pathname.new(OUTPUT_DIR).join('application.min.js')
sprockets = Sprockets::Environment.new(ROOT) do |env|
env.logger = LOGGER
end
sprockets.append_path(APP_ASSETS_DIR.join('javascripts').to_s)
sprockets.append_path(PUBLIC_ASSETS_DIR.join('javascripts').to_s)
FileUtils.mkdir_p outfile.dirname
asset = sprockets['application.js']
asset.write_to(outfile)
puts "Compiled JS assets"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment