fix(angular): handle indexHtmlTransformer option in dev-server correctly (#21520)

This commit is contained in:
Leosvel Pérez Espinosa 2024-02-02 12:00:03 +01:00 committed by GitHub
parent d6d7b1c689
commit 3b5f4a21ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 9 deletions

View File

@ -554,9 +554,10 @@
"x-priority": "important",
"additionalProperties": false
},
"indexFileTransformer": {
"indexHtmlTransformer": {
"description": "Path to transformer function to transform the index.html",
"type": "string"
"type": "string",
"alias": "indexFileTransformer"
},
"buildLibsFromSource": {
"type": "boolean",

View File

@ -44,6 +44,7 @@ type BuildTargetOptions = {
tsConfig: string;
buildLibsFromSource?: boolean;
customWebpackConfig?: { path?: string };
indexHtmlTransformer?: string;
indexFileTransformer?: string;
plugins?: string[] | PluginSpec[];
esbuildMiddleware?: string[];
@ -111,11 +112,14 @@ export function executeDevServerBuilder(
}
}
const normalizedIndexHtmlTransformer =
buildTargetOptions.indexHtmlTransformer ??
buildTargetOptions.indexFileTransformer;
let pathToIndexFileTransformer: string;
if (buildTargetOptions.indexFileTransformer) {
if (normalizedIndexHtmlTransformer) {
pathToIndexFileTransformer = joinPathFragments(
context.workspaceRoot,
buildTargetOptions.indexFileTransformer
normalizedIndexHtmlTransformer
);
if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) {
@ -313,6 +317,7 @@ function cleanBuildTargetOptions(
| BrowserEsbuildBuilderOptions {
delete options.buildLibsFromSource;
delete options.customWebpackConfig;
delete options.indexHtmlTransformer;
delete options.indexFileTransformer;
delete options.plugins;

View File

@ -4,6 +4,10 @@ export type BrowserBuilderSchema = Schema & {
customWebpackConfig?: {
path: string;
};
indexFileTransformer?: string;
indexHtmlTransformer?: string;
buildLibsFromSource?: boolean;
/**
* @deprecated Use `indexHtmlTransformer` instead. It will be removed in Nx 19.
*/
indexFileTransformer?: string;
};

View File

@ -458,9 +458,10 @@
"x-priority": "important",
"additionalProperties": false
},
"indexFileTransformer": {
"indexHtmlTransformer": {
"description": "Path to transformer function to transform the index.html",
"type": "string"
"type": "string",
"alias": "indexFileTransformer"
},
"buildLibsFromSource": {
"type": "boolean",

View File

@ -55,6 +55,7 @@ export function executeWebpackBrowserBuilder(
const {
buildLibsFromSource,
customWebpackConfig,
indexHtmlTransformer,
indexFileTransformer,
...delegateBuilderOptions
} = options;
@ -71,9 +72,11 @@ export function executeWebpackBrowserBuilder(
);
}
const normalizedIndexHtmlTransformer =
indexHtmlTransformer ?? indexFileTransformer;
const pathToIndexFileTransformer =
indexFileTransformer &&
joinPathFragments(context.workspaceRoot, indexFileTransformer);
normalizedIndexHtmlTransformer &&
joinPathFragments(context.workspaceRoot, normalizedIndexHtmlTransformer);
if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) {
throw new Error(
`File containing Index File Transformer function Not Found!\n Please ensure the path to the file containing the function is correct: \n${pathToIndexFileTransformer}`