Skip to content

Commit 3daa0a8

Browse files
committed
fix(nf): update script tags in place to respect #733
1 parent 0b27536 commit 3daa0a8

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

libs/native-federation-core/src/lib/config/federation-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface FederationConfig {
2626
externals?: string[];
2727
features?: {
2828
mappingVersion?: boolean;
29-
}
29+
};
3030
}
3131

3232
export interface NormalizedSharedConfig {
@@ -53,5 +53,5 @@ export interface NormalizedFederationConfig {
5353
externals: string[];
5454
features: {
5555
mappingVersion: boolean;
56-
}
56+
};
5757
}

libs/native-federation-core/src/lib/core/bundle-exposed-and-mappings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export async function bundleExposedAndMappings(
6363
requiredVersion: '',
6464
singleton: true,
6565
strictVersion: false,
66-
version: config.features.mappingVersion ? getMappingVersion(item.fileName) : '',
66+
version: config.features.mappingVersion
67+
? getMappingVersion(item.fileName)
68+
: '',
6769
dev: !fedOptions.dev
6870
? undefined
6971
: {

libs/native-federation-core/src/lib/core/bundle-shared.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,14 @@ export async function bundleShared(
8787
);
8888
}
8989

90-
const additionalExternals = platform === 'browser' ? DEFAULT_EXTERNAL_LIST : [];
90+
const additionalExternals =
91+
platform === 'browser' ? DEFAULT_EXTERNAL_LIST : [];
9192

9293
try {
9394
await bundle({
9495
entryPoints,
9596
tsConfigPath: fedOptions.tsConfig,
96-
external: [
97-
...additionalExternals,
98-
...externals
99-
],
97+
external: [...additionalExternals, ...externals],
10098
outdir: cachePath,
10199
mappedPaths: config.sharedMappings,
102100
dev: fedOptions.dev,

libs/native-federation-core/src/lib/core/default-external-list.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ const NODE_PACKAGES = [
2727
'zlib',
2828
];
2929

30-
export const DEFAULT_EXTERNAL_LIST = NODE_PACKAGES.flatMap(p => ([p, 'node:' + p]));
30+
export const DEFAULT_EXTERNAL_LIST = NODE_PACKAGES.flatMap((p) => [
31+
p,
32+
'node:' + p,
33+
]);

libs/native-federation/src/utils/updateIndexHtml.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,17 @@ export function updateScriptTags(
5454

5555
const htmlFragment = `
5656
<script type="esms-options">${JSON.stringify(esmsOptions)}</script>
57-
58-
<script type="module" src="${polyfillsName}"></script>
59-
<script type="module-shim" src="${mainName}"></script>
6057
`;
6158

6259
indexContent = indexContent.replace(
63-
/<script src="polyfills.*?><\/script>/,
64-
''
60+
/<script src="(.*?polyfills.*?)><\/script>/,
61+
'<script type="module" src="$1"></script>'
62+
);
63+
indexContent = indexContent.replace(
64+
/<script src="(.*?main.*?)><\/script>/,
65+
'<script type="module-shim" src="$1"></script>'
6566
);
66-
indexContent = indexContent.replace(/<script src="main.*?><\/script>/, '');
67-
indexContent = indexContent.replace('</body>', `${htmlFragment}</body>`);
67+
68+
indexContent = indexContent.replace('<body>', `<body>${htmlFragment}`);
6869
return indexContent;
6970
}

0 commit comments

Comments
 (0)