Created
July 6, 2018 03:22
-
-
Save joeldenning/841759a9ec4a37ed147a1d311705935f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The things imported with ES6 are things we want to execute right up front. | |
// The things required below are things we want to execute only when someone needs them. | |
// Switching between the two impacts performance. In general, it's better to be lazy with | |
// executing code, but there are some things we need to do right up front. | |
import SystemJS from 'systemjs' | |
if (window.sofeManifest) { | |
SystemJS.config(sofeManifest) | |
delete window.sofeManifest | |
} | |
// register sofe itself, but call it sofe-system. "sofe" will be reserved for the sofe wrapper | |
registerDep('sofe-system', () => require('sofe')) | |
// register sofe wrapper which makes sure sofe services are script tagged | |
SystemJS.registerDynamic('sofe-wrapper.js', ['system-amd-script', 'sofe-system'], false, function($__require) { | |
return {...$__require('sofe-system'), ...$__require('system-amd-script')} | |
}) | |
// Use the sofe wrapper as the sofe plugin | |
SystemJS.config({ | |
map: { | |
sofe: "sofe-wrapper.js" | |
} | |
}) | |
// register all other common deps (alphabetical) | |
registerDep('canopy-sofe-extensions', () => require('canopy-sofe-extensions')) | |
registerDep('custom-event-polyfill', () => require('custom-event-polyfill')) | |
registerDep('jquery', () => require('jquery')) | |
registerDep('lodash', () => require('lodash')) | |
registerDep('moment', () => require('moment')) | |
registerDep('prop-types', () => require('prop-types')) | |
registerDep('react', () => require('react')) | |
registerDep('react-dom', () => require('react-dom')) | |
registerDep('react-dom/server', () => require('react-dom/server')) | |
registerDep('regenerator-runtime/runtime', () => require('regenerator-runtime/runtime')) | |
registerDep('rx', () => require('rx')) | |
registerDep('single-spa', () => require('single-spa')) | |
registerDep('single-spa-canopy', () => require('single-spa-canopy')) | |
registerDep('system-amd-script', () => require('system-amd-script')) | |
registerDep('whatwg-fetch', () => require('whatwg-fetch')) | |
// A "requirer" is a function that requires a module. It is not called until | |
// a sofe service needs the dependency. This prevents the code from being executed | |
// unnecessarily during the critical initialization phase of the app | |
function registerDep(name, requirer) { | |
SystemJS.registerDynamic(name, [], false, function(_r, _e, _m) { | |
_m.exports = requirer() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment