Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 7, 2011 07:10
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/1441817 to your computer and use it in GitHub Desktop.
Save jrmoran/1441817 to your computer and use it in GitHub Desktop.
minify js and css files
# These files will be minified ...
javascripts:
- build/js/ga.js
- build/js/jquery-1.7.1.js
- build/js/portfolio.js
styles:
- build/style/screen_v3.css
# And combined into single files
outputjs: build/js/client.js
outputcss: build/style/style.css
require 'yaml'
require 'yui/compressor'
desc 'minify all the things'
task :min do
assets = YAML.load_file 'assets.yml'
outjs = File.new assets['outputjs'], 'w'
outcss = File.new assets['outputcss'], 'w'
js = assets[ 'javascripts' ].collect{ |f| IO.read("#{f}") }
css = assets[ 'styles' ].collect{ |f| IO.read("#{f}") }
js_compressor = YUI::JavaScriptCompressor.new :munge => true
css_compressor = YUI::CssCompressor.new
outjs.write js_compressor.compress( js.join ' ' )
outcss.write css_compressor.compress( css.join ' ' )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment