Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 $<'
%-min.js: %.js
@echo '==> Minifying $<'
# target: clean - Removes minified CSS and JS files.
# target: help - Displays help.
@egrep "^# target:" Makefile
Copy link

yurkobb commented Aug 11, 2012

Thank you for this Makefile! Could you, however, add some license to it? I would maybe pack it into my webproject boilerplate which I once will maybe share with people. This way I will know if I can incorporate your Makefile. Thanks once more!

Copy link

enzolutions commented Oct 28, 2013

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