Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save StanAngeloff/966484 to your computer and use it in GitHub Desktop.
Save StanAngeloff/966484 to your computer and use it in GitHub Desktop.
Makefile
build:
@@cat one.js two.js three.js | awk '{ if ($$0 ~ /<!--#include/) { match($$0, /<!--#include[[:space:]]file="([^"]+)"[[:space:]]-->/, captures); system(sprintf("cat '%s'", captures[1])) } else { print; } }' | uglifyjs -o out.min.js
@StanAngeloff
Copy link
Author

Usage:

make -B

from within your scripts directory.

What it does?

The Makefile reads three files one.js, two.js and three.js (in this order) and concatenates them in one. The result is processed so any Server-Side includes are replaced. The final output is passed to UglifyJS.

Example

one.js:

alert('Hello from one.js');
<!--#include file="lib.js" -->

lib.js:

alert('Hello from lib.js');

two.js: empty
three.js: empty

Why?

Server-Side includes are a great way to minimize your work while developing a component. No need to have Watchr monitoring and running scripts on the background for you, just let Apache deal with it.

When it comes time to deploy, run make and commit the production files.

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