From c0263d8e02ff5e3a99564d61cded5d43c45f5b43 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 11 Apr 2024 15:23:44 -0500 Subject: [PATCH 1/3] fix: Ensure sourcemap comments are stripped too --- src/prerender.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index 00e76ba..d94f744 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -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(/\n.*$/m, ""); + } } - 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)), From b3e1589d47f33b86849e8404d342a8a988ddd05d Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 11 Apr 2024 17:44:11 -0500 Subject: [PATCH 2/3] refactor: More restrictive source map regex --- src/prerender.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prerender.ts b/src/prerender.ts index d94f744..0861039 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -229,7 +229,7 @@ export function PrerenderPlugin({ if (output.endsWith(".js") && bundle[output].type == "chunk") { (bundle[output] as OutputChunk).code = (bundle[ output - ] as OutputChunk).code.replace(/\n.*$/m, ""); + ] as OutputChunk).code.replace(/\/\/#\ssourceMappingURL=.*$/, ""); } } if (!output.endsWith(".js") || bundle[output].type !== "chunk") From 7548caeb1dbe13467c92369ee8cd122df4f2dc19 Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Mon, 3 Jun 2024 07:29:57 -0500 Subject: [PATCH 3/3] Update src/prerender.ts --- src/prerender.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prerender.ts b/src/prerender.ts index 0861039..eaacade 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -229,7 +229,7 @@ export function PrerenderPlugin({ if (output.endsWith(".js") && bundle[output].type == "chunk") { (bundle[output] as OutputChunk).code = (bundle[ output - ] as OutputChunk).code.replace(/\/\/#\ssourceMappingURL=.*$/, ""); + ] as OutputChunk).code.replace(/^\/\/#\ssourceMappingURL=.*$/, ""); } } if (!output.endsWith(".js") || bundle[output].type !== "chunk")