From 0cdf390c2801f2b8dc4678898a709143204ccf30 Mon Sep 17 00:00:00 2001 From: kunish Date: Thu, 1 Feb 2024 18:21:09 +0800 Subject: [PATCH] feat: get package.json version from npm builtin environment variable --- .env | 1 + src/pages/Config.tsx | 2 +- src/vite-env.d.ts | 2 +- vite.config.ts | 5 ----- 4 files changed, 3 insertions(+), 7 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..5e01b0f --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_APP_VERSION=$npm_package_version \ No newline at end of file diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 423a0b5..99f7777 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -497,7 +497,7 @@ const Versions: Component<{ backendVersion: Accessor }> = ({ return (
- {import.meta.env.version} + {import.meta.env.VITE_APP_VERSION}
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 2dc7d14..a9fd9c4 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,5 +1,5 @@ interface ImportMetaEnv { - readonly version: string + readonly VITE_APP_VERSION: string } interface ImportMeta { diff --git a/vite.config.ts b/vite.config.ts index 22bfc04..c8a00e1 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,18 +1,13 @@ import { defineConfig, splitVendorChunkPlugin } from 'vite' import { VitePWA } from 'vite-plugin-pwa' import solidPlugin from 'vite-plugin-solid' -import pkgJSON from './package.json' export default defineConfig({ base: './', build: { chunkSizeWarningLimit: 1000 }, resolve: { alias: { '~': '/src' } }, - define: { - 'import.meta.env.version': JSON.stringify(pkgJSON.version), - }, plugins: [ solidPlugin(), - splitVendorChunkPlugin(), VitePWA({