feat: get package.json version from npm builtin environment variable

This commit is contained in:
kunish 2024-02-01 18:21:09 +08:00
parent eb6944fb2a
commit 0cdf390c28
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430
4 changed files with 3 additions and 7 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
VITE_APP_VERSION=$npm_package_version

View File

@ -497,7 +497,7 @@ const Versions: Component<{ backendVersion: Accessor<string> }> = ({
return (
<div class="grid grid-cols-2 gap-4">
<kbd class="kbd">{import.meta.env.version}</kbd>
<kbd class="kbd">{import.meta.env.VITE_APP_VERSION}</kbd>
<div class="relative">
<Show when={isUpdateAvailable()}>

2
src/vite-env.d.ts vendored
View File

@ -1,5 +1,5 @@
interface ImportMetaEnv {
readonly version: string
readonly VITE_APP_VERSION: string
}
interface ImportMeta {

View File

@ -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({