Skip to content

Commit

Permalink
feat: get package.json version from npm builtin environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Feb 1, 2024
1 parent eb6944f commit 0cdf390
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_APP_VERSION=$npm_package_version
2 changes: 1 addition & 1 deletion src/pages/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()}>
Expand Down
2 changes: 1 addition & 1 deletion src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface ImportMetaEnv {
readonly version: string
readonly VITE_APP_VERSION: string
}

interface ImportMeta {
Expand Down
5 changes: 0 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down

1 comment on commit 0cdf390

@yorunning
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.135设置中不显示版本号

Please sign in to comment.