Configure Vite to bundle all code into a single chunk using manualChunks, preventing Alpine.js from being split into multiple modules that caused "redeclaration of let Xo" errors during initialization. This resolves the critical bug where Alpine.js would load twice on pages using @Header, breaking all @click handlers and causing form buttons to fall back to default browser behavior (unwanted navigation/form submission). Technical details: - The default Vite code-splitting was creating multiple ESM chunks - Alpine's reactive system uses let Xo internally - Multiple chunks caused Xo to be declared multiple times - manualChunks() forces everything into a single bundle Fixes #XXX (Alpine.js redeclaration error)
20 lines
395 B
TypeScript
20 lines
395 B
TypeScript
import { defineConfig } from "vite";
|
|
export default defineConfig({
|
|
build: {
|
|
outDir: "web/static",
|
|
emptyOutDir: false,
|
|
rollupOptions: {
|
|
input: "web/src/main.ts",
|
|
output: {
|
|
entryFileNames: "main.js",
|
|
manualChunks: () => {
|
|
return "everything";
|
|
},
|
|
},
|
|
},
|
|
target: "es2020",
|
|
sourcemap: true,
|
|
minify: "esbuild",
|
|
},
|
|
});
|