From bb8b663ebc441e84cc946bdb1e95fe866b6ffd59 Mon Sep 17 00:00:00 2001 From: yusing Date: Wed, 11 Feb 2026 00:43:25 +0800 Subject: [PATCH] feat(build): add JavaScript minification support and use minified loading.js - Add `minify-js` target to Makefile that minifies JavaScript files in internal/ - Update `build` and `run` targets to run minification before building/running - Replace `html/loading.js` embed with `html/loading-min.js` in loading_page.go This change optimizes the loading page performance by embedding minified JavaScript instead of the full source file. The Makefile now automatically generates minified versions of JavaScript files during build and run operations. --- .gitignore | 5 ++++- Makefile | 16 +++++++++++----- internal/idlewatcher/loading_page.go | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a8262858..430fa743 100755 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,7 @@ dev-data/ RELEASE_NOTES.md CLAUDE.md -.kilocode/** \ No newline at end of file +.kilocode/** + +# minified files +**/*-min.* \ No newline at end of file diff --git a/Makefile b/Makefile index 65c56388..47a98116 100755 --- a/Makefile +++ b/Makefile @@ -117,12 +117,21 @@ mod-tidy: cd ${PWD}/$$path && go mod tidy; \ done -build: +minify-js: + for file in $$(find internal/ -name '*.js' | grep -v -- '-min\.js$$'); do \ + ext="$${file##*.}"; \ + base="$${file%.*}"; \ + min_file="$${base}-min.$$ext"; \ + echo "minifying $$file -> $$min_file"; \ + bunx --bun uglify-js $$file --compress --mangle --output $$min_file; \ + done + +build: minify-js mkdir -p $(shell dirname ${BIN_PATH}) go build -C ${PWD} ${BUILD_FLAGS} -o ${BIN_PATH} ./cmd ${POST_BUILD} -run: +run: minify-js cd ${PWD} && [ -f .env ] && godotenv -f .env go run ${BUILD_FLAGS} ./cmd dev: @@ -140,9 +149,6 @@ benchmark: sleep 1 @./scripts/benchmark.sh -dev-run: build - cd dev-data && ${BIN_PATH} - rapid-crash: docker run --restart=always --name test_crash -p 80 debian:bookworm-slim /bin/cat &&\ sleep 3 &&\ diff --git a/internal/idlewatcher/loading_page.go b/internal/idlewatcher/loading_page.go index 8fdd71a7..c06976d8 100644 --- a/internal/idlewatcher/loading_page.go +++ b/internal/idlewatcher/loading_page.go @@ -25,7 +25,7 @@ var loadingPageTmpl = template.Must(template.New("loading_page").Parse(string(lo //go:embed html/style.css var cssBytes []byte -//go:embed html/loading.js +//go:embed html/loading-min.js var jsBytes []byte func (w *Watcher) writeLoadingPage(rw http.ResponseWriter) error {