prelöoad experiment

This commit is contained in:
seb
2026-07-20 00:39:16 +02:00
parent c5b2f06919
commit 724f873bfe
10 changed files with 5596 additions and 59 deletions

45
scripts/dev.mjs Normal file
View File

@@ -0,0 +1,45 @@
/**
* Dev with full PWA precache: production build --watch + preview.
* Vite HMR cannot precache in-memory modules; use npm run dev:hmr for that.
*/
import { build, preview } from 'vite';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.dirname(fileURLToPath(import.meta.url));
const configFile = path.resolve(root, '../vite.config.js');
const watcher = await build({
configFile,
build: { watch: {} },
});
let previewServer;
async function startPreview() {
if (previewServer) return;
previewServer = await preview({
configFile,
preview: { host: true },
});
previewServer.printUrls();
previewServer.bindCLIShortcuts({ print: true });
}
watcher.on('event', (event) => {
if (event.code === 'BUNDLE_END') {
void startPreview();
}
if (event.code === 'ERROR') {
console.error(event.error);
}
});
async function shutdown() {
await previewServer?.close();
await watcher.close();
process.exit(0);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);