diff --git a/vite.config.ts b/vite.config.ts index cbe3897..069893d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -187,8 +187,12 @@ function inlineAsset(html: string, fileName: string, item: Rolldown.OutputChunk if (!scriptTag.test(html)) { return null; } + // With codeSplitting off, Vite never fills the `__VITE_PRELOAD__` deps placeholder + // it puts in each dynamic `import()` wrapper, so the first lazy import throws a + // ReferenceError (ColliderLab, MolScope). One chunk has nothing to preload, and the + // helper skips preloading when its deps argument is undefined. // Escape `` so an inlined occurrence cannot close the tag early. - const code = item.code.replace(/<\/script>/g, "<\\/script>"); + const code = item.code.replaceAll("__VITE_PRELOAD__", "void 0").replace(/<\/script>/g, "<\\/script>"); return html.replace(scriptTag, () => ``); } @@ -408,6 +412,9 @@ export default defineConfig(({ mode }) => { }, workbox: { maximumFileSizeToCacheInBytes: WORKBOX_MAX_FILE_BYTES, + // Lets /-single.html (the build:single file Baton's deploy.yml adds + // after this build) reach returning visitors instead of the fallback index.html. + navigateFallbackDenylist: [/-single\.html$/], globPatterns: [ `**/*.{${["js", "css", "html", "svg", "png", "woff2", ...simConfig.precacheExtensions].join(",")}}`, ],