mirror of
https://github.com/suitenumerique/docs.git
synced 2026-04-26 01:25:05 +02:00
fix: Ensure federated types are downloaded before type compiling/ type checking
- Adds a function to the webpack.config and documentation to make sure host types are downloaded to the plugin before the first type compile/ type check is happening Avoids an error where on cold start the types were not yet downloaded but types were already checked.
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
const path = require('path');
|
||||
const { NativeFederationTypeScriptHost } = require('@module-federation/native-federation-typescript/webpack');
|
||||
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
|
||||
const {
|
||||
NativeFederationTypeScriptHost,
|
||||
} = require('@module-federation/native-federation-typescript/webpack');
|
||||
const {
|
||||
NativeFederationTypeScriptHost: NativeFederationTypeScriptHostCore,
|
||||
} = require('@module-federation/native-federation-typescript');
|
||||
|
||||
const moduleFederationConfig = {
|
||||
name: 'plugin_frontend',
|
||||
@@ -31,6 +36,24 @@ const moduleFederationConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
let mfTypesReady;
|
||||
const ensureFederatedTypesPlugin = {
|
||||
apply(compiler) {
|
||||
compiler.hooks.beforeCompile.tapPromise(
|
||||
'EnsureFederatedTypes',
|
||||
async () => {
|
||||
if (!mfTypesReady) {
|
||||
const downloader = NativeFederationTypeScriptHostCore.raw({
|
||||
moduleFederationConfig,
|
||||
});
|
||||
mfTypesReady = downloader.writeBundle();
|
||||
}
|
||||
await mfTypesReady;
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
const dev = argv.mode !== 'production';
|
||||
|
||||
@@ -70,10 +93,11 @@ module.exports = (env, argv) => {
|
||||
new ModuleFederationPlugin(moduleFederationConfig),
|
||||
...(dev
|
||||
? [
|
||||
NativeFederationTypeScriptHost({
|
||||
moduleFederationConfig,
|
||||
}),
|
||||
]
|
||||
ensureFederatedTypesPlugin,
|
||||
NativeFederationTypeScriptHost({
|
||||
moduleFederationConfig,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user