From 574c06c754deb84953d182057ea17bba14a2bcd4 Mon Sep 17 00:00:00 2001 From: web Date: Sun, 30 Nov 2025 02:38:44 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=20Add=20version.lock=20p?= =?UTF-8?q?lugin=20to=20generate=20version=20lock=20file=20after=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/vite.config.ts | 21 ++++++++++++++++++++- apps/user/vite.config.ts | 21 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/admin/vite.config.ts b/apps/admin/vite.config.ts index 2f0c567..92cbf6f 100644 --- a/apps/admin/vite.config.ts +++ b/apps/admin/vite.config.ts @@ -1,9 +1,27 @@ +import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath, URL } from "node:url"; import tailwindcss from "@tailwindcss/vite"; import { devtools } from "@tanstack/devtools-vite"; import { tanstackRouter } from "@tanstack/router-plugin/vite"; import viteReact from "@vitejs/plugin-react"; -import { defineConfig } from "vite"; +import { defineConfig, type Plugin } from "vite"; + +// Plugin to generate version.lock file after build +function versionLockPlugin(): Plugin { + return { + name: "version-lock", + apply: "build", + closeBundle() { + const distDir = fileURLToPath(new URL("./dist", import.meta.url)); + const rootPkgPath = fileURLToPath( + new URL("../../package.json", import.meta.url) + ); + const rootPkg = JSON.parse(readFileSync(rootPkgPath, "utf-8")); + const version = rootPkg.version || "0.0.0"; + writeFileSync(`${distDir}/version.lock`, version); + }, + }; +} // https://vitejs.dev/config/ export default defineConfig({ @@ -16,6 +34,7 @@ export default defineConfig({ }), viteReact(), tailwindcss(), + versionLockPlugin(), ], resolve: { alias: { diff --git a/apps/user/vite.config.ts b/apps/user/vite.config.ts index 8fb9326..93ab006 100644 --- a/apps/user/vite.config.ts +++ b/apps/user/vite.config.ts @@ -1,9 +1,27 @@ +import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath, URL } from "node:url"; import tailwindcss from "@tailwindcss/vite"; import { devtools } from "@tanstack/devtools-vite"; import { tanstackRouter } from "@tanstack/router-plugin/vite"; import viteReact from "@vitejs/plugin-react"; -import { defineConfig } from "vite"; +import { defineConfig, type Plugin } from "vite"; + +// Plugin to generate version.lock file after build +function versionLockPlugin(): Plugin { + return { + name: "version-lock", + apply: "build", + closeBundle() { + const distDir = fileURLToPath(new URL("./dist", import.meta.url)); + const rootPkgPath = fileURLToPath( + new URL("../../package.json", import.meta.url) + ); + const rootPkg = JSON.parse(readFileSync(rootPkgPath, "utf-8")); + const version = rootPkg.version || "0.0.0"; + writeFileSync(`${distDir}/version.lock`, version); + }, + }; +} // https://vitejs.dev/config/ export default defineConfig({ @@ -16,6 +34,7 @@ export default defineConfig({ }), viteReact(), tailwindcss(), + versionLockPlugin(), ], resolve: { alias: {