public
Last active — forked from rgrove/Makefile

Simple Makefile to minify CSS and JS.

  • Download Gist
Makefile
Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
# 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 \
))
 
# Set css minifier and flags
CSS_COMPRESSOR = csstidy
CSS_COMPRESSOR_FLAGS = --discard_invalid=false \
--template=highest
 
# Set javascript minifier and flags
JS_COMPRESSOR = uglifyjs
JS_COMPRESSOR_FLAGS =
 
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 css file $<'
$(CSS_COMPRESSOR) $< $(CSS_COMPRESSOR_FLAGS) >$@
@echo
 
%-min.js: %.js
@echo '==> Minifying javascript file $<'
$(JS_COMPRESSOR) $(JS_COMPRESSOR_FLAGS) -o >$@ $<
@echo
 
# target: clean - Removes minified CSS and JS files.
clean:
rm -f $(CSS_MINIFIED) $(JS_MINIFIED)
 
# target: help - Displays help.
help:
@egrep "^# target:" Makefile

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.