summaryrefslogtreecommitdiff
path: root/assets/Makefile
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-02 08:06:50 +0200
committerhref <href@random.sh>2021-09-02 08:06:50 +0200
commit1fbd63419355e8ddd482c3cb62641bed1366763b (patch)
tree370ce63fcf19f2fd8b1f5136fc19a317050ba0f3 /assets/Makefile
parenttxt: don't search in files with dot, display them below in web (diff)
Phoenix 1.6rc0 & Use proper Esbuild/Tailwind/Npm
Diffstat (limited to 'assets/Makefile')
-rw-r--r--assets/Makefile62
1 files changed, 62 insertions, 0 deletions
diff --git a/assets/Makefile b/assets/Makefile
new file mode 100644
index 0000000..02a4048
--- /dev/null
+++ b/assets/Makefile
@@ -0,0 +1,62 @@
+NODE ?= node
+NPM ?= npm
+NPX ?= npx
+RM ?= rm
+GZIP ?= gzip
+TOUCH ?= touch
+BROTLI ?= brotli
+ESBUILD ?= node_modules/esbuild/bin/esbuild
+CONCURRENTLY ?= node_modules/concurrently/bin/concurrently.js
+
+FILES = ../priv/static/assets/site.css ../priv/static/assets/site.js ../priv/static/assets/alcoolog.js
+
+FILES_GZ := $(addsuffix .gz, $(FILES))
+FILES_BR := $(addsuffix .br, $(FILES))
+FILES_CONTROLLERS := $(shell find controllers/ -name '*.js')
+
+.PHONY: all
+all: node_modules $(FILES) $(FILES_GZ) $(FILES_BR)
+
+node_modules: package.json package-lock.json
+ $(NPM) install
+ @$(TOUCH) node_modules
+
+../priv/static/assets/%.css: %.css
+ NODE_ENV=production $(NPX) tailwindcss --postcss --minify -i $< -o $@
+
+../priv/static/assets/%.js: %.js $(FILES_CONTROLLERS) script/build.%.js
+ #NODE_ENV=production $(ESBUILD) $< --bundle --minify --target=es2016 --outfile=$@
+ NODE_ENV=production $(NODE) script/build.$<
+
+../priv/static/assets/%.js.gz: ../priv/static/assets/%.js
+ $(GZIP) --force --best --keep $<
+ @$(TOUCH) $@
+
+../priv/static/assets/%.css.gz: ../priv/static/assets/%.css
+ $(GZIP) --force --best --keep $<
+ @$(TOUCH) $@
+
+../priv/static/assets/%.js.br: ../priv/static/assets/%.js
+ $(BROTLI) --force --best --keep $<
+ @$(TOUCH) $@
+
+../priv/static/assets/%.css.br: ../priv/static/assets/%.css
+ $(BROTLI) --force --best --keep $<
+ @$(TOUCH) $@
+
+.PHONY: clean
+clean:
+ $(RM) $(FILES) $(FILES_GZ) $(FILES_BR)
+
+.PHONY: watch
+watch: #watch_css watch_js
+ $(CONCURRENTLY) --kill-others -n css,js "make watch_css" "make watch_js"
+
+.PHONY: watch_css
+watch_css:
+ NODE_ENV=development $(NPX) tailwindcss --input=site.css --output=assets/site.css --postcss --watch
+
+.PHONY: watch_js
+watch_js:
+ #NODE_ENV=development $(ESBUILD) site.js --bundle --sourcemap=inline --watch --outfile=assets/site.js
+ NODE_ENV=development $(NODE) script/watch.site.js