From f97b139fda9cb634fc7a3684c6704afb2cb932c1 Mon Sep 17 00:00:00 2001 From: divyakarippath Date: Mon, 10 Aug 2020 09:25:09 -0700 Subject: [PATCH] Load cdn mapping script for non js/css assets only if cdn option isenabled (#1716) * load cdn mapping script only if cdn is enabled * refactoring --- packages/subapp-web/lib/init.js | 5 ++++- packages/subapp-web/src/subapp-web.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/subapp-web/lib/init.js b/packages/subapp-web/lib/init.js index 81e9c4aaf5..3e5aa6e06a 100644 --- a/packages/subapp-web/lib/init.js +++ b/packages/subapp-web/lib/init.js @@ -10,9 +10,12 @@ const _ = require("lodash"); const assert = require("assert"); module.exports = function setup(setupContext) { + const cdnEnabled = _.get(setupContext, "routeOptions.cdn.enable"); const distDir = process.env.NODE_ENV === "production" ? "../dist/min" : "../dist/dev"; const clientJs = Fs.readFileSync(Path.join(__dirname, distDir, "subapp-web.js")).toString(); - const cdnJs = Fs.readFileSync(Path.join(__dirname, distDir, "cdn-map.js")).toString(); + const cdnJs = cdnEnabled + ? Fs.readFileSync(Path.join(__dirname, distDir, "cdn-map.js")).toString() + : ""; const loadJs = Fs.readFileSync(require.resolve("loadjs/dist/loadjs.min.js"), "utf8"); // // TODO: in webpack dev mode, we need to reload stats after there's a change diff --git a/packages/subapp-web/src/subapp-web.js b/packages/subapp-web/src/subapp-web.js index bc947dd4d8..9ffdc7f4a1 100644 --- a/packages/subapp-web/src/subapp-web.js +++ b/packages/subapp-web/src/subapp-web.js @@ -1,6 +1,10 @@ // xarc subapp client side lib version 1 // load into window.xarcV1 as a global (function (w) { + if (!w._wml) { + w._wml = {}; + } + const version = 1000000; // ###.###.### major.minor.patch if (w.xarcV1 && w.xarcV1.version >= version) return w.xarcV1;