Skip to content

Instantly share code, notes, and snippets.

@TheHippo
Created March 17, 2013 22:18
Show Gist options
  • Save TheHippo/5183896 to your computer and use it in GitHub Desktop.
Save TheHippo/5183896 to your computer and use it in GitHub Desktop.
Compile and compress multiple Coffee-Script files into a single one, including a working source map
# adjust these path to where ever the executables are
COFFEE_BIN = ./node_modules/.bin/coffee
UGLIFY_BIN = ./node_modules/.bin/uglifyjs
# https://github.com/edc/mapcat
MAPCAT_BIN = ./node_modules/.bin/mapcat
# Where your coffee files are
INPUT_FOLDER = ./input
# Where you want your output
OUTPUT_FOLDER = ./output
# Filename for the uncompressed JavaScript
FILE_NAME = alljavascript.js
OUTPUT_FILE = $(OUTPUT_FOLDER)/$(FILE_NAME)
COFFEE_FILES = $(shell ls $(INPUT_FOLDER)/*.coffee)
all: coffee
# I love typing "make coffee" into my terminal
coffee:
$(COFFEE_BIN) --bare --compile --map $(COFFEE_FILES)
$(MAPCAT_BIN) $(COFFEE_FILES:.coffee=.map) --jsout $(OUTPUT_FILE) --mapout $(OUTPUT_FILE:.js=.map)
-@rm $(COFFEE_FILES:.coffee=.map) $(COFFEE_FILES:.coffee=.js)
$(UGLIFY_BIN) --compress --mangle \
--in-source-map $(OUTPUT_FILE:.js=.map) \
--source-map $(OUTPUT_FILE:.js=.min.map) \
--output $(OUTPUT_FILE:.js=.min.js) \
--source-map-url $(OUTPUT_FILE:$(OUTPUT_FOLDER)/%.js=%.min.map) \
--source-map-root file://$(shell pwd)/$(OUTPUT_FOLDER)
clean:
-rm $(OUTPUT_FOLDER)/*.js
-rm $(OUTPUT_FOLDER)/*.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment