|
#========================================================== |
|
# Environment/Configuration |
|
#========================================================== |
|
|
|
# For project consistency, its better to depend on npm binaries loaded locally than |
|
# globally, so we add .node_modules/.bin to the path for shorthand references. This |
|
# means you should add any binaries you need to "devDependencies" in package.json. |
|
export PATH := ./node_modules/.bin/:$(PATH) |
|
|
|
# Since we depend on node already, we can use it in a mini shell script to automatically |
|
# pull in the name and version from package.json. The name will default to "app" if not set. |
|
NAME ?= $(shell node -e "console.log(require('./package.json').name || 'app');") |
|
VERSION = $(shell node -e "console.log(require('./package.json').version);") |
|
|
|
# Here we configure the names of our project's directories. Feel free to |
|
# overload for your own setup. You'll need to follow the convention that there |
|
# are "main.js" and "main.less" files in the root of the SRC directory. |
|
DIR ?= . |
|
SRC ?= ./src |
|
SRC_STATIC ?= $(SRC)/assets |
|
DEST ?= ./dist |
|
DEST_JS ?= $(DEST)/js |
|
DEST_CSS ?= $(DEST)/css |
|
|
|
# Here set some options for our binaries |
|
BROWSERIFY_OPTS ?= "-t [hbsfy -e html]" |
|
UGLIFY_OPTS ?= "" |
|
|
|
#========================================================== |
|
# Livereload |
|
#========================================================== |
|
|
|
# http://github.com/mklabs/make-livereload |
|
# make-livereload uses the tiny-lr server written in node and curl for |
|
# triggering changes. |
|
LIVERELOAD_DIR ?= $(DEST) |
|
include ./node_modules/make-livereload/index.mk |
|
|
|
#========================================================== |
|
# Default |
|
#========================================================== |
|
|
|
default: build |
|
|
|
#========================================================== |
|
# Phony targets |
|
#========================================================== |
|
|
|
.PHONY: clean compress develop static build |
|
|
|
#========================================================== |
|
# Tasks |
|
#========================================================== |
|
|
|
# Clean the build directory |
|
clean: |
|
rm -rf $(DEST)/* |
|
|
|
# Build all dynamic assets |
|
build: static $(DEST_JS)/$(NAME).js $(DEST_CSS)/$(NAME).css |
|
|
|
# Copy over all static assets |
|
static: $(wildcard, $(SRC_STATIC)/*, $(SRC_STATIC)/**/*) |
|
mkdir -p $(DEST) $(DEST_JS) $(DEST_CSS) |
|
cp -av $(SRC_STATIC)/* $(DEST)/ |
|
|
|
# Minify built assets |
|
compress: build $(DEST_JS)/$(NAME).min.js $(DEST_CSS)/$(NAME).min.css |
|
|
|
# Startup web server and LiveReload server. |
|
develop: build |
|
$(MAKE) livereload |
|
serve ./dist & |
|
watch $(MAKE) --quiet reload |
|
|
|
#========================================================== |
|
# JS Build Targets |
|
#========================================================== |
|
|
|
# Local javascript build |
|
$(DEST_JS)/$(NAME).js: $(SRC)/main.js $(wildcard $(SRC)/*.js $(SRC)/**/*.js) |
|
browserify $(BROSERIFY_OPTS) $(SRC)/main.js > $(DEST_JS)/$(NAME).js |
|
|
|
# Concat and minify scripts |
|
$(DEST_JS)/$(NAME).min.js: $(DEST_JS)/$(NAME).js |
|
cat $(DEST_JS)/$(NAME).js | uglifyjs $(UGLIFY_OPTS) -o $(DEST_JS)/$(NAME).min.js |
|
|
|
#========================================================== |
|
# CSS Build Targets |
|
#========================================================== |
|
|
|
# Compile LESS files |
|
$(DEST_CSS)/$(NAME).css: $(SRC)/main.less $(wildcard $(SRC)/*.less, $(SRC)/**/*.less) |
|
lessc $(SRC)/main.less > $(DEST_CSS)/$(NAME).css |
|
|
|
# Minify CSS |
|
$(DEST_CSS)/$(NAME).min.css: $(DEST_CSS)/$(NAME).css |
|
csso $(DEST_CSS)/$(NAME).css > $(DEST_CSS)/$(NAME).min.css |