Skip to content

Commit 10b85e0

Browse files
committed
Step 2 - Add support for custom index.html modification function
1 parent 9d781c6 commit 10b85e0

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BuildExecutorSchema } from '../build/schema';
77
import { ConfigMf } from '../types';
88
import { workspaceRootPath } from './utils';
99
import { externalMap, getFullShare, getSharedMappings } from './dependencies';
10+
import { loadModule } from './load-module';
1011

1112
export async function prepareConfig(
1213
defaultOptions: SchemaMf['mf'],
@@ -16,6 +17,7 @@ export async function prepareConfig(
1617
const skipList: ConfigMf['skipList'] = [];
1718
const externalList: ConfigMf['externalList'] = [];
1819
const esPlugins: ConfigMf['esPlugins'] = [];
20+
let indexHtmlTransformer = (input: string) => Promise.resolve(input);
1921

2022
if (defaultOptions.skipList) {
2123
skipList.push(...(await checkIsFileOrArray(defaultOptions.skipList)));
@@ -42,6 +44,14 @@ export async function prepareConfig(
4244
esPlugins.push(...tmpEsPlugins);
4345
}
4446

47+
if (defaultOptions.indexHtmlTransformer) {
48+
indexHtmlTransformer = await loadModule(
49+
join(workspaceRootPath, defaultOptions.indexHtmlTransformer),
50+
join(workspaceRootPath, `${buildOptions['tsConfig']}`),
51+
context.logger
52+
);
53+
}
54+
4555
return {
4656
skipList: skipList,
4757
externalList: externalList,
@@ -52,6 +62,7 @@ export async function prepareConfig(
5262
outPutFileNames: [],
5363
esPlugins,
5464
allImportMap: {},
65+
indexHtmlTransformer
5566
};
5667
}
5768

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export type SchemaMf = {
33
skipList?: string | string[];
44
externalList?: string | string[];
55
esPlugins?: string[];
6+
indexHtmlTransformer?: string;
67
};
78
};

libs/nx-angular-mf/src/builders/schema/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"items": {
4242
"type": "string"
4343
}
44+
},
45+
"indexHtmlTransformer": {
46+
"type": "string"
4447
}
4548
},
4649
"additionalProperties": false

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export async function* runBuilder(
9898

9999

100100
const transforms = {
101-
indexHtml: mainTransform,
101+
indexHtml: async (input: string) => {
102+
const mainTransformResult = await mainTransform(input);
103+
return optionsMfe.indexHtmlTransformer(mainTransformResult);
104+
},
102105
};
103106

104107
const runServer = serveWithVite(

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

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

1112
export type ShareOptions = {

0 commit comments

Comments
 (0)