From 80126c76f39d30917b94f24b97a8690681b815c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 1 Aug 2022 00:47:02 +0200 Subject: Change JavaScript build system to esbuild. Esbuild is way faster, and feels less hacky. One downside is that it doesn't actually check Typescript types. However, typescript can still be installed alongside, and has the fancy --noEmit flag for just this situation. --- module/calp/html/view/calendar.scm | 2 +- static/Makefile | 23 +++++++++++++++-------- static/make-watch | 5 ++--- static/package.json | 10 ++++------ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/module/calp/html/view/calendar.scm b/module/calp/html/view/calendar.scm index 9378737f..99109741 100644 --- a/module/calp/html/view/calendar.scm +++ b/module/calp/html/view/calendar.scm @@ -119,7 +119,7 @@ window.default_calendar='~a';" ,(include-alt-css "/static/dark.css" '(title "Dark")) ,(include-alt-css "/static/light.css" '(title "Light")) - (script (@ (src "/static/script.out.js"))) + (script (@ (src "/static/script.js"))) (script (@ (src "/static/user/user-additions.js"))) (style ,(lambda () (calendar-styles calendars #t))) diff --git a/static/Makefile b/static/Makefile index 0c6023b0..c348b3a8 100644 --- a/static/Makefile +++ b/static/Makefile @@ -1,22 +1,29 @@ -.PHONY: all install clean watch +.PHONY: all install clean watch watch-esbuild -TARGETS := style.css smallcal.css script.out.js directory-listing.css +TARGETS := style.css smallcal.css script.js directory-listing.css WATCH= TS_FILES = $(shell find . -type f -name \*.ts -not -path */node_modules/*) JS_FILES = $(TS_FILES:%.ts=%.js) +ESBUILD_LOGLEVEL=warning +# Variable for adding extra flags +ESBUILD_FLAGS = +# Used flags +__ESBUILD_FLAGS = --log-level=$(ESBUILD_LOGLEVEL) \ + --sourcemap --bundle --outdir=$(CURDIR) \ + $(ESBUILD_FLAGS) + export PATH := $(shell npm bin):$(PATH) all: $(TARGETS) -%.map.json: %.out.js - tail -n1 $< | tail -c+65 | base64 --decode | jq '.' > $@ - -# r!browserify --list script.ts -p tsify | xargs -L1 basename | tac # script explicitly named, since that is our entry point -script.out.js: script.ts $(TS_FILES) - browserify $< -p tsify --noImplicitAny --debug -o $@ +script.js: script.ts $(TS_FILES) + esbuild $< $(__ESBUILD_FLAGS) + +watch-esbuild: + $(MAKE) ESBUILD_FLAGS+='--watch' ESBUILD_LOGLEVEL=info -B script.js deps.svg: $(TS_FILES) madge --image $@ $^ diff --git a/static/make-watch b/static/make-watch index c985b37f..b328038a 100755 --- a/static/make-watch +++ b/static/make-watch @@ -8,15 +8,14 @@ cd "$here" || { export PATH="$here/node_modules/.bin:$PATH" -# Note that 'tsc --watch' doesn't provide the files we are using. It's -# just here for debug. if [ -n "$TMUX" ]; then tmux new-window "scss --watch -I. style.scss:style.css" tmux new-window "tsc --watch" else tmux \ new-session "scss --watch -I. style.scss:style.css" \; \ - split-window "tsc --watch" \; \ + split-window "tsc --watch --noEmit" \; \ + split-window "make watch-esbuild" \; \ rename-session "calp watch" \; \ select-layout even-vertical diff --git a/static/package.json b/static/package.json index 27ea218a..81db3a61 100644 --- a/static/package.json +++ b/static/package.json @@ -1,13 +1,11 @@ { - "dependencies": { - "browserify": "^17.0.0", - "tsify": "^5.0.4" - }, "devDependencies": { - "@types/uuid": "^8.3.1", - "uuid": "^8.3.2" + "@types/uuid": "^8.3.1" }, "optionalDependencies": { "madge": "^5.0.1" + }, + "dependencies": { + "uuid": "^8.3.2" } } -- cgit v1.2.3