Skip to content

Instantly share code, notes, and snippets.

@scarfacedeb
Last active August 29, 2015 13:56
Show Gist options
  • Save scarfacedeb/9213888 to your computer and use it in GitHub Desktop.
Save scarfacedeb/9213888 to your computer and use it in GitHub Desktop.
Conditional uglifier to skip optimization on specific files
# in config/environments/production.rb
require 'ext/conditional_uglifier'
# Compress JavaScripts and CSS.
config.assets.js_compressor = ConditionalUglifier.new
# in lib/ext/conditional_uglifier.rb
class ConditionalUglifier < Uglifier
def really_compile(source, generate_map)
# Skip any optimization (e.g. for shims)
if source =~ /^\/\/= skip/
source.gsub!(/\/\/= ?skip(\n)*;(\n)*\z/, "")
else
super
end
end
end
# An example of shims.js
//= skip
//= require shims/classList.min
//= require shims/raf.min
//= require shims/weakmap.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment