fix(make): пересобирать изменившийся фронтенд в make run
Цель run зависела только от backend, а статика фронтенда попадает в бинарник через go:embed из backend/static, который обновляла лишь цель frontend. Поэтому make run пересобирал Go-код со старым UI. - run теперь зависит от frontend backend; - frontend стала инкрементальной: npm ci только при изменении package.json/ package-lock.json, npm run build и копирование в backend/static — только когда исходники или конфиги новее, чем backend/static/index.html (он же stamp); - проверки вынесены в shell-recipe, т.к. имена SvelteKit-роутов вида (app) ломают разбор имён файлов в make.
This commit is contained in:
@@ -32,10 +32,44 @@ help:
|
||||
@echo "Available targets:"
|
||||
@grep -hE '^[a-zA-Z0-9_-]+:' $(MAKEFILE_LIST) | cut -d: -f1 | sed 's/^/ /'
|
||||
|
||||
# Frontend sources whose changes must trigger a rebuild. `backend/static/index.html`
|
||||
# doubles as the build stamp, so a clean clone or `make clean` (which empties
|
||||
# backend/static) forces the next build to regenerate.
|
||||
FRONTEND_OUT := backend/static/index.html
|
||||
|
||||
# `npm ci` is only needed when the manifest/lockfile change.
|
||||
FRONTEND_DEPS_STAMP := frontend/node_modules/.install-stamp
|
||||
|
||||
# Build the SvelteKit bundle and copy it into backend/static (embedded via
|
||||
# go:embed). Incremental: recompile only when frontend sources are newer than the
|
||||
# embedded bundle. Paths are checked from the recipe (not as make prerequisites)
|
||||
# because SvelteKit route names like `(app)` break make's filename parsing.
|
||||
frontend:
|
||||
cd frontend && npm ci && npm run build
|
||||
rm -rf backend/static/*
|
||||
cp -r frontend/build/* backend/static/
|
||||
@set -e; \
|
||||
if [ ! -f $(FRONTEND_DEPS_STAMP) ] \
|
||||
|| [ frontend/package.json -nt $(FRONTEND_DEPS_STAMP) ] \
|
||||
|| [ frontend/package-lock.json -nt $(FRONTEND_DEPS_STAMP) ]; then \
|
||||
echo '> cd frontend && npm ci'; \
|
||||
cd frontend && npm ci; \
|
||||
touch node_modules/.install-stamp; \
|
||||
cd ..; \
|
||||
fi; \
|
||||
if [ ! -f $(FRONTEND_OUT) ] \
|
||||
|| [ -n "$$(find frontend/src frontend/static -newer $(FRONTEND_OUT) -print -quit)" ] \
|
||||
|| [ frontend/package.json -nt $(FRONTEND_OUT) ] \
|
||||
|| [ frontend/package-lock.json -nt $(FRONTEND_OUT) ] \
|
||||
|| [ frontend/svelte.config.js -nt $(FRONTEND_OUT) ] \
|
||||
|| [ frontend/vite.config.ts -nt $(FRONTEND_OUT) ] \
|
||||
|| [ frontend/tailwind.config.ts -nt $(FRONTEND_OUT) ] \
|
||||
|| [ frontend/tsconfig.json -nt $(FRONTEND_OUT) ]; then \
|
||||
echo '> cd frontend && npm run build'; \
|
||||
cd frontend && npm run build; \
|
||||
cd ..; \
|
||||
rm -rf backend/static/*; \
|
||||
cp -r frontend/build/* backend/static/; \
|
||||
else \
|
||||
echo 'frontend: up to date'; \
|
||||
fi
|
||||
|
||||
backend:
|
||||
mkdir -p bin
|
||||
@@ -87,7 +121,7 @@ build-release: frontend
|
||||
cp bin/galo bin/galo-$(VERSION)
|
||||
@echo "release: bin/galo-$(VERSION)"
|
||||
|
||||
run: backend
|
||||
run: frontend backend
|
||||
./bin/galo
|
||||
|
||||
migrate:
|
||||
|
||||
Reference in New Issue
Block a user