Skip to content

Commit

Permalink
Load cdn mapping script for non js/css assets only if cdn option isen…
Browse files Browse the repository at this point in the history
…abled (electrode-io#1716)

* load cdn mapping script only if cdn is enabled

* refactoring
  • Loading branch information
divyakarippath authored and ImgBotApp committed Aug 20, 2020
1 parent 570b2cc commit f97b139
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/subapp-web/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/subapp-web/src/subapp-web.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit f97b139

Please sign in to comment.