Skip to content

Commit

Permalink
refactor: Skip second loop, delete from bundle earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Feb 22, 2024
1 parent d1a2486 commit 775e26d
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,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 Expand Up @@ -407,14 +412,5 @@ export function PrerenderPlugin({
});
}
},
async writeBundle(_opts, bundle) {
if (!userEnabledSourceMaps) {
Object.keys(bundle)
.filter(f => /\.map$/.test(f))
.forEach(async f => {
fs.rm(path.join(viteConfig.root, viteConfig.build.outDir, f));
});
}
},
};
}

0 comments on commit 775e26d

Please sign in to comment.