Last active
September 28, 2022 17:15
-
-
Save derekdon/bad1211c869e1dfbf350d377a87a0ec4 to your computer and use it in GitHub Desktop.
WP5 Module Federation TS Fallback Design
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
import { designSystemImport } from './designSystem'; | |
const registerCommonComponents = async () => { | |
const { | |
provideDesignSystem, | |
componentA, | |
componentB, | |
} = await designSystemImport(); | |
provideDesignSystem().register( | |
componentA(), | |
componentB(), | |
); | |
}; |
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
/** | |
* 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`); | |
} | |
} |
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
"dependencies": { | |
"@genesislcap/foundation-zero": "^1.0.0", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.