From 6713cc8e2f221f27552740e4660f6afd7bccc3e3 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Wed, 21 Oct 2020 17:57:50 -0700 Subject: [PATCH] fix: map CDN urls for webpack4's jsonp bundle loading --- packages/subapp-web/lib/init.js | 9 ++ packages/subapp-web/lib/util.js | 104 ++++++++++++++-------- packages/subapp-web/src/webpack4-jsonp.js | 13 +++ 3 files changed, 88 insertions(+), 38 deletions(-) create mode 100644 packages/subapp-web/src/webpack4-jsonp.js diff --git a/packages/subapp-web/lib/init.js b/packages/subapp-web/lib/init.js index deec5c8f2..4b3d47d84 100644 --- a/packages/subapp-web/lib/init.js +++ b/packages/subapp-web/lib/init.js @@ -37,6 +37,14 @@ module.exports = function setup(setupContext) { basePath: "" }; + // For subapp version 2, when using to do dynamic import, + // code to translate for webpack 4 jsonp bundle loading. + // requires processing done by xarc-webpack/src/plugins/jsonp-script-src-plugin + // TBD: need to update when upgrade to webpack 5 + const webpackJsonpJS = cdnEnabled + ? Fs.readFileSync(Path.join(__dirname, distDir, "webpack4-jsonp.js")).toString() + : ""; + let inlineRuntimeJS = ""; let runtimeEntryPoints = []; if (process.env.NODE_ENV === "production") { @@ -60,6 +68,7 @@ module.exports = function setup(setupContext) { ${JSON.stringify(bundleAssets)}