From 4307955163410e6cebf17dea3444a929a1795415 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Mon, 27 Apr 2026 15:38:10 +0300 Subject: [PATCH] feat(frontend): inject __APP_VERSION__ from package.json at build time - vite.config.ts: read package.json and expose its version as a build-time global via Vite's `define`. - app.d.ts: add ambient declaration so the layout's brand version badge (`v{__APP_VERSION__}`) type-checks. --- frontend/src/app.d.ts | 16 ++++++++++++++++ frontend/vite.config.ts | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 frontend/src/app.d.ts diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts new file mode 100644 index 0000000..412c565 --- /dev/null +++ b/frontend/src/app.d.ts @@ -0,0 +1,16 @@ +// Ambient type declarations for SvelteKit + project-level build-time globals. + +declare global { + /** App version, injected from frontend/package.json at build time. */ + const __APP_VERSION__: string; + + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } +} + +export {}; diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 777997b..8bd35e9 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,9 +1,18 @@ import { sveltekit } from '@sveltejs/kit/vite'; import tailwindcss from '@tailwindcss/vite'; import { defineConfig } from 'vite'; +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; + +const pkg = JSON.parse( + readFileSync(fileURLToPath(new URL('./package.json', import.meta.url)), 'utf8'), +); export default defineConfig({ plugins: [tailwindcss(), sveltekit()], + define: { + __APP_VERSION__: JSON.stringify(pkg.version), + }, server: { port: 5175, proxy: {