Search code examples
javascriptpreprocessorconcatenationguarduglifyjs

Concatenate & minify directory of JS files into one JS file with Guard and UglifyJS


I have a folder of JS plugins that i would like to concatenate and minify into a plugins.js file using Guard and UglifyJS

Here's what I have in my Guardfile so far

guard 'uglify', :input => 'js-unprocessed/plugins/*.js', :output => "assets/plugins.js" do
  watch 'js-unprocessed/plugins/*.js'
end

I'd expect something to happen when I save one of the JS files in the plugins directory but I don't get any feedback in the console and no files are updated or created.

Please let me know if you think Guard and UglifyJS are not the right tools for the job.


Solution

  • I used https://github.com/guard/guard-jammit which did the trick.

    I needed to add a config/assets.yml file with this:

    embed_assets: on
    
    javascripts:
      plugins:
        - js-unprocessed/plugins/*.js
    

    and then added this to my Guardfile

    guard :jammit, :output_folder => "assets/"  do
      watch(%r{^js-unprocessed/plugins/(.*)\.js$})
    end