Files
shakespeare/vite.config.ts
T
Alex Gleason 369ab0bf1e Use custom protocol handler instead of base: './'
This is a much cleaner solution that eliminates the need for:
- Changing base: './' in vite.config.ts
- Importing assets in components
- Any workarounds for absolute paths

How it works:
- Register app:// protocol in Electron main process
- Maps app://path/to/file to dist/path/to/file
- Allows absolute paths (/) to work naturally in Electron
- No changes needed to source code or build config

Benefits:
- vite.config.ts stays clean (no base: './' hack)
- Components use normal paths: src="/shakespeare.svg"
- Works in both browser (https://) and Electron (app://)
- This is the standard Electron approach for serving local files

Reverted:
- vite.config.ts: Removed base: './'
- ShakespeareLogo: Back to src="/shakespeare.svg"
- AppShowcaseCard: Back to src="/badge.svg"

Updated:
- electron/main.js: Added protocol.registerFileProtocol('app', ...)
- electron/main.js: Changed loadURL to app://index.html
2025-10-24 19:59:16 -05:00

71 lines
1.8 KiB
TypeScript

import { execSync } from "node:child_process";
import path from "node:path";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vitest/config";
function getVersion(): string {
try {
const gitCommit = execSync('git rev-parse --short HEAD').toString().trim();
const commitTimestamp = execSync('git log -1 --format=%ct').toString().trim();
const commitDate = new Date(parseInt(commitTimestamp) * 1000);
const utcDate = commitDate.toISOString().split('T')[0].replace(/-/g, '.');
return `${utcDate}+${gitCommit}`;
} catch {
return new Date().toISOString().split('T')[0].replace(/-/g, '.');
}
}
// https://vitejs.dev/config/
export default defineConfig(() => ({
server: {
host: "::",
port: 8080,
},
define: {
'import.meta.env.VERSION': JSON.stringify(getVersion()),
},
plugins: [
react(),
],
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
// get the path after "node_modules/"
const parts = id.toString().split('node_modules/')[1].split('/');
// handle scoped packages (@scope/name)
const pkgName = parts[0].startsWith('@')
? `${parts[0]}/${parts[1]}`
: parts[0];
return `npm/${pkgName.replace('@', '')}`;
}
if (id.includes('/src/')) {
return 'app';
}
},
},
},
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
onConsoleLog(log) {
return !log.includes("React Router Future Flag Warning");
},
env: {
DEBUG_PRINT_LIMIT: '0', // Suppress DOM output that exceeds AI context windows
},
css: true
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
}));