import type webpack from 'webpack' ; import type { Compiler } from 'webpack' ; const PLUGIN_NAME = 'ModuleFederationIgnoreEntires' ; export interface ModuleFederationIgnoreEntriesOptions { entries : string [ ] ; } /**
 * Temporary fix of usage ModuleFederation with multiple entries
 * [open discussion](https://github.com/webpack/webpack/discussions/14985) how to do it properly
 */ export class ModuleFederationIgnoreEntries implements webpack . WebpackPluginInstance { protected entries : Set < string > ; constructor ( options ) { this . entries = new Set ( options . entries ) ; } apply ( compiler ) { compiler . hooks . thisCompilation . tap ( PLUGIN_NAME , ( compilation ) => { compilation . hooks . beforeChunks . tap ( PLUGIN_NAME , ( ) => { const { includeDependencies } = compilation . globalEntry ; for ( const [ entryName , entry ] of compilation . entries ) { if ( ! this . entries . has ( entryName ) ) { entry . includeDependencies . push ( ... includeDependencies ) ; } } compilation . globalEntry . includeDependencies = [ ] ; } ) ; compilation . hooks . additionalTreeRuntimeRequirements . intercept ( { register : ( tap ) => { if ( tap . name === 'ConsumeSharedPlugin' ) { const originalFn = tap . fn ; tap . fn = ( chunk , ... args ) => { if ( ! this . entries . has ( chunk . name ) ) { originalFn ( chunk , ... args ) ; } } ; } return tap ; } , } ) ; } ) ; } }