Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created November 12, 2020 08:42
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 ryancdotorg/5470ae2bc4157f9c8cffbaaaaa47dcd6 to your computer and use it in GitHub Desktop.
Save ryancdotorg/5470ae2bc4157f9c8cffbaaaaa47dcd6 to your computer and use it in GitHub Desktop.
A Makefile for bundling javascript
all: javascript
javascript: bundle_js min_js
bundle_js: $(patsubst %/,%.bundle.js,$(foreach js,$(sort $(dir $(wildcard src/js/*/*.js))),$(subst src/,static/,$(js))))
min_js: $(patsubst %.js,%.min.js,$(foreach js,$(wildcard src/js/*.js),$(subst src/,static/,$(js))))
static/js/%.min.js: src/js/%.js
terser $< --safari10 --ecma 5 -c passes=2 -m --mangle-props regex=/^_/ -o $@
clean:
rm static/js/*.js 2> /dev/null || true
.PHONY: all clean javascript bundle_js min_js
.SECONDARY:
.SECONDEXPANSION:
static/js/%.bundle.js: $$(sort $$(wildcard src/js/$$*/*.js))
terser $^ --safari10 --ecma 5 -c passes=2 -m --mangle-props regex=/^_/ \
-e window,document,location,navigator:window,document,location,navigator \
-o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment