1+ import { execSync } from 'node:child_process' ;
12import { defineConfig , type Plugin } from 'vite' ;
23import react from '@vitejs/plugin-react' ;
34import legacy from '@vitejs/plugin-legacy' ;
@@ -10,8 +11,32 @@ import pkg from './package.json';
1011// Single source of truth for supported browsers; drives which polyfills the
1112// legacy plugin injects (see the `legacy` plugin below).
1213const browserslist = pkg . browserslist ;
14+ // A per-build version stamp, baked in as `__SOURCE_VERSION__`. Used to cache-bust
15+ // the runtime-fetched locale JSONs (their URLs are otherwise fixed, so a CDN /
16+ // browser keeps serving a stale copy after a deploy — a half-translated UI).
17+ // Resolution order, most authoritative first:
18+ // - SOURCE_VERSION commit SHA — injected by Scalingo's buildpack natively,
19+ // and passed as a build-arg from our CI Docker build
20+ // - `git` local builds / any context that ships the .git dir
21+ // - timestamp last-resort, still unique from one deploy to the next
22+ const appVersion =
23+ process . env . SOURCE_VERSION ||
24+ ( ( ) => {
25+ try {
26+ return execSync ( 'git rev-parse --short HEAD' , {
27+ stdio : [ 'ignore' , 'pipe' , 'ignore' ] ,
28+ } )
29+ . toString ( )
30+ . trim ( ) ;
31+ } catch {
32+ return `t${ Date . now ( ) } ` ;
33+ }
34+ } ) ( ) ;
1335
1436export default defineConfig ( {
37+ define : {
38+ __SOURCE_VERSION__ : JSON . stringify ( appVersion ) ,
39+ } ,
1540 plugins : [
1641 // See ./tsr.config.json for tanstackRouter config
1742 tanstackRouter ( ) ,
0 commit comments