diff --git a/src/prerender.ts b/src/prerender.ts index 73a7922..d8d9a4e 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -76,6 +76,7 @@ export function PrerenderPlugin({ }: PrerenderPluginOptions = {}): Plugin { const preloadHelperId = "vite/preload-helper"; let viteConfig = {} as ResolvedConfig; + let userEnabledSourceMaps: boolean | undefined; renderTarget ||= "body"; additionalPrerenderRoutes ||= []; @@ -118,6 +119,7 @@ export function PrerenderPlugin({ apply: "build", enforce: "post", configResolved(config) { + userEnabledSourceMaps = !!config.build.sourcemap; // Enable sourcemaps for generating more actionable error messages config.build.sourcemap = true; @@ -219,6 +221,11 @@ export function PrerenderPlugin({ let prerenderEntry: OutputChunk | undefined; for (const output of Object.keys(bundle)) { + // Clean up source maps if the user didn't enable them themselves + if (/\.map$/.test(output) && !userEnabledSourceMaps) { + delete bundle[output]; + continue; + } if (!/\.js$/.test(output) || bundle[output].type !== "chunk") continue; await fs.writeFile(