Skip to content

Commit

Permalink
fix: isomorphic-loader 4.0.3 and CDN mapping support
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Oct 22, 2020
1 parent 6713cc8 commit d9c831d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
4 changes: 4 additions & 0 deletions packages/subapp-pbundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.7.7",
"@xarc/app": "^8.1.20",
"babel-preset-minify": "^0.5.1",
"electrode-archetype-njs-module-dev": "^3.0.0",
"jsdom": "^15.2.1",
Expand All @@ -57,6 +58,9 @@
"dependencies": {
"subapp-web": "../subapp-web",
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
}
},
"nyc": {
Expand Down
4 changes: 4 additions & 0 deletions packages/subapp-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.7.7",
"@xarc/app": "^8.1.20",
"babel-preset-minify": "^0.5.1",
"electrode-archetype-njs-module-dev": "^3.0.0",
"jsdom": "^15.2.1",
Expand All @@ -60,6 +61,9 @@
"dependencies": {
"subapp-web": "../subapp-web",
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
}
},
"nyc": {
Expand Down
18 changes: 18 additions & 0 deletions packages/subapp-web/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const subappUtil = require("subapp-util");
const _ = require("lodash");
const assert = require("assert");

const { getXRequire } = require("@xarc/app").isomorphicLoader;

module.exports = function setup(setupContext) {
const cdnEnabled = _.get(setupContext, "routeOptions.cdn.enable");
const distDir = process.env.NODE_ENV === "production" ? "../dist/min" : "../dist/dev";
Expand Down Expand Up @@ -92,6 +94,22 @@ ${inlineRuntimeJS}
.filter(x => x && x.initialize));
};

const setupIsomorphicCdnUrlMapping = () => {
const extRequire = getXRequire();
if (!extRequire) return;
const cdnAssets = util.loadCdnAssets(setupContext.routeOptions);
const cdnKeys = Object.keys(cdnAssets).map(k => Path.basename(k));

extRequire.setUrlMapper(url => {
const urlBaseName = Path.basename(url);
return (cdnKeys.includes(urlBaseName) && cdnAssets[urlBaseName]) || url;
});
};

if (cdnEnabled) {
setupIsomorphicCdnUrlMapping();
}

return {
process: context => {
context.user.assets = assets;
Expand Down
11 changes: 9 additions & 2 deletions packages/subapp-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,32 @@
"subapp-util": "^1.1.1",
"xaa": "^1.6.0"
},
"peerDependencies": {
"@xarc/app": "^8.1.20"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.7.7",
"@xarc/app": "^8.1.20",
"babel-preset-minify": "^0.5.1",
"chai-as-promised": "^7.1.1",
"electrode-archetype-njs-module-dev": "^3.0.0",
"electrode-react-webapp": "^3.8.9",
"jsdom": "^15.2.1",
"mock-require": "^1.3.0",
"run-verify": "^1.2.2",
"subapp-pkg-util": "../subapp-pkg-util",
"electrode-react-webapp": "^3.8.9"
"subapp-pkg-util": "../subapp-pkg-util"
},
"fyn": {
"dependencies": {
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
}
},
"nyc": {
Expand Down
2 changes: 1 addition & 1 deletion packages/xarc-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@babel/runtime": "^7.8.3",
"css-modules-require-hook": "^4.0.2",
"ignore-styles": "^5.0.1",
"isomorphic-loader": "^4.0.2",
"isomorphic-loader": "^4.0.3",
"optional-require": "^1.0.0",
"subapp-util": "^1.1.1"
},
Expand Down
17 changes: 2 additions & 15 deletions packages/xarc-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,9 @@ export function cssModuleHook(
* Load the require hook to support isomorphic assets when doing SSR
*/
export function isomorphicExtendRequire() {
const appSrcDir = (getAppMode().getEnv() || getAppMode().lib.dir).split("/")[0];
const xReq = extendRequire({
processConfig: (isoConfig: any) => {
const { assets } = isoConfig;
const appSrcDir = (getAppMode().getEnv() || getAppMode().lib.dir).split("/")[0];
if (appSrcDir !== getAppMode().src.dir && assets.marked) {
const marked = assets.marked;
Object.keys(marked).forEach(k => {
if (k.startsWith(getAppMode().src.client) || k.startsWith(getAppMode().src.server)) {
const nk = k.replace(getAppMode().src.dir, appSrcDir);
marked[nk] = marked[k];
}
});
}

return isoConfig;
}
appSrcDir
});

setXRequire(xReq);
Expand Down
1 change: 1 addition & 0 deletions packages/xarc-webpack/src/partials/isomorphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function(opts) {
const { IsomorphicLoaderPlugin } = xAppRequire("isomorphic-loader");

const plugin = new IsomorphicLoaderPlugin({
appSrcDir: xarcOptions.AppMode.src.dir,
assetsFile: opts.assetsFile || "../isomorphic-assets.json",
webpackDev: {
url: `http://${xarcOptions.webpack.devHostname}:${xarcOptions.webpack.devPort}`,
Expand Down

0 comments on commit d9c831d

Please sign in to comment.