Skip to content

Instantly share code, notes, and snippets.

@zleight1
Created October 12, 2022 08:24
Show Gist options
  • Save zleight1/76dfb7b894ea2458d5f297c02380825f to your computer and use it in GitHub Desktop.
Save zleight1/76dfb7b894ea2458d5f297c02380825f to your computer and use it in GitHub Desktop.
single-spa root config trying for on-demand bundle loading
import {
constructRoutes,
constructApplications,
constructLayoutEngine,
} from "single-spa-layout";
import { registerApplication, start } from "single-spa";
const routes = constructRoutes(document.querySelector("#single-spa-layout"), {
loaders: {
topNav: "<h1>Loading topnav</h1>",
},
errors: {
topNav: "<h1>Failed to load topnav</h1>",
},
});
const applications = constructApplications({
routes,
loadApp: ({ name }) => System.import(name),
});
// Delay starting the layout engine until the styleguide CSS is loaded
const layoutEngine = constructLayoutEngine({
routes,
applications,
active: false,
});
applications.forEach(registerApplication);
System.import("@react-mf/styleguide").then(() => {
// start single-spa before the engine?
start();
// Activate the layout engine once the styleguide CSS is loaded
layoutEngine.activate();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment