[!NOTE] Pattern storico: L'uso di GNU Make come pipeline di asset frontend era diffuso prima che Vite, Webpack ed esbuild diventassero standard. Rimane un approccio leggero per progetti semplici.
Pattern di compilazione di base
bin := ./node_modules/.bin
all: build/app.js
build/%.js: src/%.coffee
@mkdir -p $(@D)
@$(bin)/coffee < $< > $@
Pipeline CSS con Stylus e Autoprefixer
bin := ./node_modules/.bin
stylus := $(bin)/stylus
autoprefixer := $(bin)/autoprefixer
styl_files := $(shell find web/ -name "*.styl")
all: public/app.css
public/app.css: css/app.styl $(styl_files)
@mkdir -p $(@D)
@$(stylus) $< | $(autoprefixer) -b "> 1%" > $@
Ciclo di monitoraggio dei file (File Watching Loop)
Un semplice ciclo shell per rieseguire i target make alle modifiche dei file:
watch:
@echo "... watching for file changes"
@while true; do make -s; sleep 1; done
Bundling JavaScript con Browserify
js_files := $(shell find web/ -name "*.js")
public/app.js: web/app.js $(js_files)
@mkdir -p $(@D)
@$(browserify) -t [ cssify -x .css ] $< > $@