Skip to content

Instantly share code, notes, and snippets.

@derekdon
Last active September 28, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekdon/bad1211c869e1dfbf350d377a87a0ec4 to your computer and use it in GitHub Desktop.
Save derekdon/bad1211c869e1dfbf350d377a87a0ec4 to your computer and use it in GitHub Desktop.
WP5 Module Federation TS Fallback Design
import { designSystemImport } from './designSystem';
const registerCommonComponents = async () => {
const {
provideDesignSystem,
componentA,
componentB,
} = await designSystemImport();
provideDesignSystem().register(
componentA(),
componentB(),
);
};
/**
* Zero design system import
*
* @public
* @remarks
* Attempts to use a module federation version of zero before falling back to the version that was bundled with the app.
*/
export async function designSystemImport(): Promise<any> {
let type: ResourceType = ResourceType.remote;
try {
return await import(
/* webpackChunkName: "foundation-zero" */
'foundationZero/ZeroDesignSystem'
);
} catch (e) {
logger.info(
`Please note remoteEntry.js load errors are expected if module federated dependencies are offline. Falling back to locally bundled versions.`
);
type = ResourceType.local;
return await import(
/* webpackChunkName: "foundation-zero" */
'@genesislcap/foundation-zero'
);
} finally {
logger.debug(`Using '${type}' version of foundation-zero`);
}
}
"dependencies": {
"@genesislcap/foundation-zero": "^1.0.0",
}
@derekdon
Copy link
Author

derekdon commented Sep 28, 2022

Not that it's relevant to the pattern here... but if you're curious, the awesome https://github.com/microsoft/fast/ project is providing the baseline for the components and the design system in this example. If you haven't used it, check it out, Rob and team have done an amazing job on FAST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment