File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed
Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 1- // Import version from the root package.json
2- // This will be bundled at build time
3- import { version } from '../../../package.json' ;
4-
5- // Export the version for use in the app
6- export const APP_VERSION = version ;
1+ // Get version from Vite environment variable that's injected at build time
2+ // This is a more reliable approach than direct importing package.json
3+ export const APP_VERSION = import . meta. env . APP_VERSION || '1.0.2' ;
Original file line number Diff line number Diff line change 1+ // / <reference types="vite/client" />
2+
3+ interface ImportMetaEnv {
4+ readonly APP_VERSION : string ;
5+ }
6+
7+ interface ImportMeta {
8+ readonly env : ImportMetaEnv ;
9+ }
Original file line number Diff line number Diff line change 2828 },
2929 "include" : [
3030 " ./" ,
31- " ../package.json"
3231 ]
3332}
Original file line number Diff line number Diff line change 11import react from '@vitejs/plugin-react-swc' ;
2+ import fs from 'fs' ;
3+ import { resolve } from 'path' ;
24import { defineConfig } from 'vite' ;
35
6+ // Read the version from the root package.json
7+ const packageJson = JSON . parse (
8+ fs . readFileSync ( resolve ( __dirname , '../package.json' ) , 'utf-8' )
9+ ) ;
10+
411// https://vite.dev/config/
512export default defineConfig ( {
613 plugins : [ react ( ) ] ,
714 server : {
815 port : 2022
916 } ,
17+ define : {
18+ // Inject the version as a global variable
19+ 'import.meta.env.APP_VERSION' : JSON . stringify ( packageJson . version ) ,
20+ } ,
1021 // build: {
1122 // rollupOptions: {
1223 // output: {
You can’t perform that action at this time.
0 commit comments