Skip to content

Commit

Permalink
fix: Ensure sourcemap comments are stripped (#118)
Browse files Browse the repository at this point in the history
* fix: Ensure sourcemap comments are stripped too

* refactor: More restrictive source map regex

* Update src/prerender.ts
  • Loading branch information
rschristian committed Jun 3, 2024
1 parent aef0301 commit 29dbe95
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,19 @@ 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 (!userEnabledSourceMaps) {
if (output.endsWith(".map")) {
delete bundle[output];
continue;
}
if (output.endsWith(".js") && bundle[output].type == "chunk") {
(bundle[output] as OutputChunk).code = (bundle[
output
] as OutputChunk).code.replace(/^\/\/#\ssourceMappingURL=.*$/, "");
}
}
if (!/\.js$/.test(output) || bundle[output].type !== "chunk") continue;
if (!output.endsWith(".js") || bundle[output].type !== "chunk")
continue;

await fs.writeFile(
path.join(tmpDir, path.basename(output)),
Expand Down

0 comments on commit 29dbe95

Please sign in to comment.