Skip to content

Commit

Permalink
fix: separate chunk for runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
MadaraUchiha-314 committed Jan 29, 2024
1 parent 5115478 commit 2d050bf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/rollup-plugin-module-federation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const FEDERATED_IMPORT_EXPR: string = 'loadShare';
const FEDERATED_IMPORT_FROM_REMOTE: string = 'loadRemote';
const FEDERATED_EAGER_SHARED: string = '__federated__shared__eager__';

const FEDERATION_RUNTIME_PACKAGE = '@module-federation/runtime';
const FEDERATION_RUNTIME_PACKAGE_CHUNK_NAME = '__module_federation_runtime__';

const MODULE_VERSION_UNSPECIFIED: string = '0.0.0';

const __filename: string = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -620,6 +623,14 @@ export default function federation(
if (id === REMOTE_ENTRY_MODULE_ID) {
return REMOTE_ENTRY_MODULE_ID;
}
/**
* We need to forcefully create a separate chunk for the @module-federation/runtime package
* Rollup shouldn't include this with any other modules as those might include top-level awaits calls to loadShare or loadRemote
* These calls cannot be present before the container is initialized.
*/
if (id.includes(FEDERATION_RUNTIME_PACKAGE)) {
return FEDERATION_RUNTIME_PACKAGE_CHUNK_NAME;
}
const resolvedModulePath = getModulePathFromResolvedId(id);
if (
Object.prototype.hasOwnProperty.call(
Expand Down

0 comments on commit 2d050bf

Please sign in to comment.