Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created July 30, 2011 22:01
Show Gist options
  • Save rgrove/1116056 to your computer and use it in GitHub Desktop.
Save rgrove/1116056 to your computer and use it in GitHub Desktop.
Simple Makefile to minify CSS and JS.
# Patterns matching CSS files that should be minified. Files with a -min.css
# suffix will be ignored.
CSS_FILES = $(filter-out %-min.css,$(wildcard \
public/css/*.css \
public/css/**/*.css \
))
# Patterns matching JS files that should be minified. Files with a -min.js
# suffix will be ignored.
JS_FILES = $(filter-out %-min.js,$(wildcard \
public/js/*.js \
public/js/**/*.js \
))
# Command to run to execute the YUI Compressor.
YUI_COMPRESSOR = java -jar yuicompressor-2.4.6.jar
# Flags to pass to the YUI Compressor for both CSS and JS.
YUI_COMPRESSOR_FLAGS = --charset utf-8 --verbose
CSS_MINIFIED = $(CSS_FILES:.css=-min.css)
JS_MINIFIED = $(JS_FILES:.js=-min.js)
# target: minify - Minifies CSS and JS.
minify: minify-css minify-js
# target: minify-css - Minifies CSS.
minify-css: $(CSS_FILES) $(CSS_MINIFIED)
# target: minify-js - Minifies JS.
minify-js: $(JS_FILES) $(JS_MINIFIED)
%-min.css: %.css
@echo '==> Minifying $<'
$(YUI_COMPRESSOR) $(YUI_COMPRESSOR_FLAGS) --type css $< >$@
@echo
%-min.js: %.js
@echo '==> Minifying $<'
$(YUI_COMPRESSOR) $(YUI_COMPRESSOR_FLAGS) --type js $< >$@
@echo
# target: clean - Removes minified CSS and JS files.
clean:
rm -f $(CSS_MINIFIED) $(JS_MINIFIED)
# target: help - Displays help.
help:
@egrep "^# target:" Makefile
@enzolutions
Copy link

Hi rgrove

Can you explain how to use this make?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment