diff --git a/lib/bundle_fu.rb b/lib/bundle_fu.rb index d3df052..49b4834 100644 --- a/lib/bundle_fu.rb +++ b/lib/bundle_fu.rb @@ -27,7 +27,12 @@ def bundle_js_files(filenames=[], options={}) output = "" bundle_files(filenames) { |filename, content| if options[:compress] - JSMinimizer.minimize_content(content) + if Object.const_defined?("Packr") + # use Packr plugin (http://blog.jcoglan.com/packr/) + Packr.new.pack(content, options[:packr_options] || {:shrink_vars => false, :base62 => true}) + else + JSMinimizer.minimize_content(content) + end else content end diff --git a/test/functional/bundle_fu_test.rb b/test/functional/bundle_fu_test.rb index 6f25e19..3a60599 100644 --- a/test/functional/bundle_fu_test.rb +++ b/test/functional/bundle_fu_test.rb @@ -20,6 +20,31 @@ def test__bundle_js_files__should_include_js_content assert_public_files_match("/javascripts/cache/bundle.js", "function js_1()") end + def test__bundle_js_files__should_use_packr + Object.send :class_eval, < {:packr_options_here => "hi_packr"}) { @@content_include_all } + assert_public_files_match("/javascripts/cache/bundle.js", "packr_options_here", "Should include packr_options") + + + Object.send :remove_const, "Packr" + + end + def test__bundle_js_files__should_default_to_not_compressed_and_include_override_option @mock_view.bundle() { @@content_include_all } default_content = File.read(public_file("/javascripts/cache/bundle.js"))