Skip to content

Commit

Permalink
Merge pull request #109 from preactjs/refactor/clean-some-sourcemaps
Browse files Browse the repository at this point in the history
refactor: Clean sourcemaps in newer Vite versions
  • Loading branch information
rschristian committed Feb 22, 2024
2 parents 0db4c5b + 775e26d commit a25a252
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||= [];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a25a252

Please sign in to comment.