From e347ba23294a0e974b3a49bb4d27b467dac3aa54 Mon Sep 17 00:00:00 2001 From: Anarios Date: Sun, 18 Oct 2026 14:35:58 +0200 Subject: [PATCH] Remove dangling source-map references from production bundles --- webpack.config.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/webpack.config.js b/webpack.config.js index 6f37cd1..f3ec259 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -107,6 +107,27 @@ class ExtensionBuildReceiptPlugin { } } +class StripSourceMapReferencesPlugin { + apply(compiler) { + compiler.hooks.thisCompilation.tap("StripSourceMapReferencesPlugin", (compilation) => { + compilation.hooks.processAssets.tap( + { + name: "StripSourceMapReferencesPlugin", + stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE, + }, + (assets) => { + for (const [name, asset] of Object.entries(assets)) { + if (!name.endsWith(".js")) continue; + const source = asset.source().toString(); + const cleaned = source.replace(/^\/\/[#@] sourceMappingURL=.*(?:\r?\n|$)/gm, ""); + if (cleaned !== source) compilation.updateAsset(name, new webpack.sources.RawSource(cleaned)); + } + }, + ); + }); + } +} + module.exports = (env = {}, argv = {}) => { const liveTestBuild = env.liveTest === true || env.liveTest === "true"; let discussionTestOrigin = ""; @@ -160,6 +181,7 @@ module.exports = (env = {}, argv = {}) => { }, plugins: [ new ExtensionBuildReceiptPlugin(buildMode), + ...(buildMode === "production" ? [new StripSourceMapReferencesPlugin()] : []), new webpack.DefinePlugin({ __RYD_LIVE_BUILD_ID__: JSON.stringify(liveBuildId), __RYD_LIVE_TEST_BUILD__: JSON.stringify(liveTestBuild),