Skip to content

Commit 596a372

Browse files
committed
Step 2 - Support deployUrl for importmap paths; default to dev-server host if absent, ensuring CDN compatibility.
1 parent db82bfc commit 596a372

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

build-skip-list.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@angular/animations/browser/testing",
1616
"@angular/common/http/testing",
1717
"@angular/common/testing",
18+
"@angular/common/upgrade",
1819
"@angular/core/testing",
1920
"@angular/ssr/node",
2021
"rxjs/testing",

libs/nx-angular-mf/src/builders/helpers/prepare-config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function prepareConfig(
2020
const remoteEntry: ConfigMf['remoteEntry'] = defaultOptions.remoteEntry || {};
2121
const exposes: ConfigMf['exposes'] = {};
2222

23+
let deployUrl = '';
2324
let indexHtmlTransformer = (input: string) => Promise.resolve(input);
2425

2526
if (defaultOptions.skipList) {
@@ -64,6 +65,10 @@ export async function prepareConfig(
6465
}
6566
}
6667

68+
if (buildOptions.deployUrl) {
69+
deployUrl = buildOptions.deployUrl;
70+
}
71+
6772
return {
6873
skipList: skipList,
6974
externalList: externalList,
@@ -76,7 +81,8 @@ export async function prepareConfig(
7681
allImportMap: {},
7782
indexHtmlTransformer,
7883
remoteEntry,
79-
exposes
84+
exposes,
85+
deployUrl
8086
};
8187
}
8288

libs/nx-angular-mf/src/builders/helpers/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ export function getDataForImportMap(
4949
const mapShareObject = getMapName(mfeConfig.shared, mfeConfig.sharedMappings);
5050
return {
5151
imports: [...mapShareObject.entries()].reduce((acum, [key, val]) => {
52+
const resultName =
53+
mfeConfig.outPutFileNames.find((i) => i.startsWith(key)) || key + '.js';
5254

53-
acum[val.packageName] = `./${key}.js`;
54-
55+
acum[val.packageName] = `${mfeConfig.deployUrl}${resultName}`;
5556
return acum;
5657
}, {}),
5758
exposes: Object.entries(mfeConfig.exposes).reduce((acum, [key, val]) => {

libs/nx-angular-mf/src/builders/serve/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ export async function* runBuilder(
6262
context
6363
);
6464

65+
if (!optionsMfe.deployUrl) {
66+
const deployUrl = new URL('http://localhost');
67+
deployUrl.port = options.port.toString();
68+
deployUrl.hostname = options.host;
69+
deployUrl.protocol = options.ssl ? 'https' : 'http';
70+
optionsMfe.deployUrl = deployUrl.toString();
71+
}
72+
6573
const mapShareObject = getMapName(
6674
optionsMfe.shared,
6775
optionsMfe.sharedMappings

libs/nx-angular-mf/src/builders/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type ConfigMf = {
55
sharedMappings: { key: string; path: string }[];
66
outPutFileNames: string[];
77
esPlugins: string[];
8+
deployUrl: string;
89
allImportMap: Record<string, unknown>;
910
indexHtmlTransformer: (input: string) => Promise<string>;
1011
exposes: Record<string, string>;

0 commit comments

Comments
 (0)