From 011ed65c1c3e5758ebc39d56b5a4eb258f8b9909 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Tue, 4 Feb 2025 00:57:37 -0600 Subject: [PATCH] Disable HMR in ES modules when outputSystemJS option is omitted (#440) --- .changeset/rich-ghosts-happen.md | 5 +++++ .../lib/webpack-config-single-spa.js | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/rich-ghosts-happen.md diff --git a/.changeset/rich-ghosts-happen.md b/.changeset/rich-ghosts-happen.md new file mode 100644 index 0000000..6f0d219 --- /dev/null +++ b/.changeset/rich-ghosts-happen.md @@ -0,0 +1,5 @@ +--- +"webpack-config-single-spa": patch +--- + +Fix bug where HMR was mistakenly enabled when outputSystemJS option was omitted diff --git a/packages/webpack-config-single-spa/lib/webpack-config-single-spa.js b/packages/webpack-config-single-spa/lib/webpack-config-single-spa.js index c2b5026..b649fd6 100644 --- a/packages/webpack-config-single-spa/lib/webpack-config-single-spa.js +++ b/packages/webpack-config-single-spa/lib/webpack-config-single-spa.js @@ -39,6 +39,8 @@ function webpackConfigSingleSpa(opts) { let HtmlWebpackPlugin = opts.HtmlWebpackPlugin || _HtmlWebpackPlugin; + const outputSystemJS = !!opts.outputSystemJS; + return { mode: isProduction ? "production" : "development", entry: path.resolve( @@ -51,7 +53,7 @@ function webpackConfigSingleSpa(opts) { path: path.resolve(process.cwd(), "dist"), uniqueName: opts.projectName, devtoolNamespace: `${opts.projectName}`, - publicPath: opts.outputSystemJS ? "" : "auto", + publicPath: outputSystemJS ? "" : "auto", }, module: { rules: [ @@ -123,7 +125,7 @@ function webpackConfigSingleSpa(opts) { }, }, allowedHosts: "all", - hot: opts.outputSystemJS, + hot: outputSystemJS, }, externals: opts.orgPackagesAsExternal ? ["single-spa", new RegExp(`^@${opts.orgName}/`)] @@ -132,7 +134,7 @@ function webpackConfigSingleSpa(opts) { new BundleAnalyzerPlugin({ analyzerMode: webpackConfigEnv.analyze ? "server" : "disabled", }), - opts.outputSystemJS && + outputSystemJS && new SystemJSPublicPathPlugin({ systemjsModuleName: `@${opts.orgName}/${opts.projectName}`, rootDirectoryLevel: opts.rootDirectoryLevel, @@ -155,7 +157,7 @@ function webpackConfigSingleSpa(opts) { extensions: [".mjs", ".js", ".jsx", ".wasm", ".json"], }, experiments: { - outputModule: !opts.outputSystemJS, + outputModule: !outputSystemJS, }, }; }