Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Last active July 11, 2025 20:15
Show Gist options
  • Select an option

  • Save toolmantim/6200029 to your computer and use it in GitHub Desktop.

Select an option

Save toolmantim/6200029 to your computer and use it in GitHub Desktop.
An example of using Make instead of Grunt for fast, simple and maintainable front-end asset compilation.

Example usage:

npm install
mkdir -p javascripts sass public
echo 'console.log("Hello world");' > javascripts/myapp.js
echo 'html { background: papayawhip; }' > sass/myapp.scss
make watch

And then look in public to see your compiled files.

APP=myapp
APP_JS_SOURCES=$(BOWER)/angular/angular.js $(JS)/signoff.js
AUTOPREFIXER_BROWSERS="> 1%"
BIN=node_modules/.bin
BOWER=bower_components
DIST=public
SASS=sass
JS=javascripts
all: $(DIST)/$(APP).css $(DIST)/$(APP).js
$(DIST)/$(APP).css:
$(BIN)/node-sass $(SASS)/$(APP).scss $(DIST)/$(APP).css
$(BIN)/autoprefixer --browsers $(AUTOPREFIXER_BROWSERS) $(DIST)/$(APP).css
$(DIST)/$(APP).js:
cat $(APP_JS_SOURCES) > $(DIST)/$(APP).js
clean:
rm -f $(DIST)/$(APP).css $(DIST)/$(APP).js
watch:
$(BIN)/nodemon --watch sass --watch javascripts --delay .25 --exec make clean all sass/*
{
"name": "myapp",
"version": "0.0.0",
"devDependencies": {
"nodemon": "x",
"autoprefixer": "x",
"node-sass": "x"
}
}
@rafaelcanovas
Copy link

Awesome use of Make! It's somewhat more difficult to configure, but the advantages are clear.

@sshelagh
Copy link

I think you have a typo in your example makefile. On line 82 you have
$(BIN)/wach -o "$(JS)//*,$(SASS)//*" make all
where wach should be watch.

@sshelagh
Copy link

but I should also say thank you for the gist.

@STRML
Copy link

STRML commented Jul 7, 2014

@sshelagh It actually is wach.

@quantuminformation
Copy link

great, I'm tired of re-learning js build tools

@SerkanSipahi
Copy link

instead using of $(BIN)/node-sass or a other service you can declare top of your makefile:

export PATH := $(PATH):$(PWD)/node_modules/.bin

then you have you write just node-sass, autoprefixer, etc. :)

@marlun
Copy link

marlun commented Feb 28, 2015

Note that adding node_modules/.bin after your default PATH will run globally installed tools instead of the locally installed ones if they are installed in both places.

@daiyi
Copy link

daiyi commented Feb 17, 2017

Make automatically watches files for changes! You can run watch make all to use unix watch to run make every 2 seconds and it will recompile on modification and you won't have to install wach :D

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