|
| 1 | +# Include this file into your makefile to bring in the following targets: |
| 2 | +# |
| 3 | +# - start - Start the LiveReload server |
| 4 | +# - stop - Stops the LiveReload server |
| 5 | +# - livereload - alias to start |
| 6 | +# - livereload-stop - aias to stop |
| 7 | +# |
| 8 | +# Then define your "empty" targets, and the list of files you want to monitor. |
| 9 | +# |
| 10 | +# CSS_DIR = app/styles |
| 11 | +# CSS_FILES = $(shell find $(CSS_DIR) -name '*.css') |
| 12 | +# |
| 13 | +# $(CSS_DIR): $(CSS_FILES) |
| 14 | +# @echo CSS files changed: $? |
| 15 | +# @touch $@ |
| 16 | +# curl -X POST http://localhost:35729/changed -d '{ "files": "$?" }' |
| 17 | +# |
| 18 | +# reload-css: livereload $(CSS_DIR) |
| 19 | +# |
| 20 | +# .PHONY: reload-css |
| 21 | +# |
| 22 | +# The pattern is always the same, define a target for your root directory that |
| 23 | +# triggers a POST request and `touch` the directory to update its mtime, a |
| 24 | +# reload target with `livereload` target and the list of files to "watch" as |
| 25 | +# prerequisites |
| 26 | +# |
| 27 | +# You can chain multiple "reload" targets in a single one: |
| 28 | +# |
| 29 | +# reload: reload-js reload-css reload-img reload-EVERYTHING |
| 30 | + |
| 31 | +# add tiny-lr to your PATH (only affect the Makefile environment) |
| 32 | +PATH := ./node_modules/.bin:$(PATH) |
| 33 | + |
| 34 | +tiny-lr.pid: |
| 35 | + @echo ... Starting server, running in background ... |
| 36 | + @echo ... Run: "make stop" to stop the server ... |
| 37 | + @tiny-lr & |
| 38 | + |
| 39 | +start: tiny-lr.pid |
| 40 | + |
| 41 | +stop: |
| 42 | + @[ -a tiny-lr.pid ] && curl http://localhost:35729/kill |
| 43 | + # Or: @[ -a tiny-lr.pid ] && kill $(shell cat tiny-lr.pid) |
| 44 | + |
| 45 | +livereload: start |
| 46 | +livereload-stop: stop |
| 47 | + |
| 48 | + |
| 49 | +.PHONY: start stop livereload livereload-stop |
0 commit comments