package.json's version is hand-maintained and never changes between builds, so a bug report can't identify which bundle produced it. Vite's `define` injects __EDITOR_BUILD__ (short git SHA + build date) at compile time; editorBuild() in build-stamp.ts is the only safe way to read it, falling back to 'dev' since vitest does not apply Vite's `define` and the identifier is otherwise undeclared. The execSync call falls back to 'nogit' when building outside a git checkout (release tarballs), verified by building from a directory with no git ancestry at all. Also wires editorBuild() into a startup console.log in main.tsx -- without any reference to it, Vite tree-shakes the unused module out of the bundle entirely and __EDITOR_BUILD__ never gets substituted, silently leaving every bug report saying 'dev'. Task 19 will add the real call site when it assembles the report payload. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import path from 'path'
|
|
import { execSync } from 'child_process'
|
|
|
|
/** Short git SHA + build date, injected as __EDITOR_BUILD__ so an issue
|
|
* report identifies exactly which bundle produced it. package.json's
|
|
* version is hand-maintained and never changes between builds. */
|
|
const editorBuild = (() => {
|
|
let sha = 'nogit'
|
|
try {
|
|
sha = execSync('git rev-parse --short HEAD', { cwd: __dirname }).toString().trim()
|
|
} catch {
|
|
// Building outside a git checkout (release tarball) -- keep 'nogit'.
|
|
}
|
|
return `${sha}-${new Date().toISOString().slice(0, 10)}`
|
|
})()
|
|
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
base: './',
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
define: {
|
|
__EDITOR_BUILD__: JSON.stringify(editorBuild),
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: 'js/editor.js',
|
|
chunkFileNames: 'js/[name].js',
|
|
assetFileNames: (info) =>
|
|
info.name?.endsWith('.css') ? 'css/editor.css' : 'assets/[name][extname]',
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
'/api': 'http://192.168.1.148:8080',
|
|
},
|
|
},
|
|
})
|