summaryrefslogblamecommitdiff
path: root/assets/Makefile
blob: 5a376d92e847abec9134ffe010a1455ab490bfe4 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                                                      
                                             







                                                  
                                                                                    































                                                                                         
                                                                                                                          


                
                                                                                                                            
                                                         
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')
FILES_CSS := $(shell find css/ -name '*.css')

.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 $(FILES_CSS) tailwind.config.js postcss.config.js
	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=../priv/static/assets/site.css --postcss --watch

.PHONY: watch_js
watch_js:
	#NODE_ENV=development $(ESBUILD) site.js --bundle --sourcemap=inline --watch --outfile=../priv/static/assets/site.js
	NODE_ENV=development $(NODE) script/watch.site.js