feat(web): add generateIndexHtml option to web build executor (#5843)

This commit is contained in:
Jack Hsu 2021-05-31 10:33:01 -04:00 committed by GitHub
parent d3c45b32b9
commit 12ee3bce97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 2 deletions

View File

@ -102,6 +102,14 @@ Type: `string`
The file to replace with.
### generateIndexHtml
Default: `true`
Type: `boolean`
Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`
### index
Type: `string`

View File

@ -103,6 +103,14 @@ Type: `string`
The file to replace with.
### generateIndexHtml
Default: `true`
Type: `boolean`
Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`
### index
Type: `string`

View File

@ -103,6 +103,14 @@ Type: `string`
The file to replace with.
### generateIndexHtml
Default: `true`
Type: `boolean`
Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`
### index
Type: `string`

View File

@ -404,6 +404,8 @@ describe('index.html interpolation', () => {
const distPath = `dist/apps/${appName}`;
const resultIndexContents = readFile(`${distPath}/index.html`);
expect(resultIndexContents).toBe(expectedBuiltIndex);
expect(resultIndexContents).toMatch(/<div>Nx Variable: foo<\/div>/);
expect(resultIndexContents).toMatch(/<div>Nx Variable: foo<\/div>/);
expect(resultIndexContents).toMatch(/ <div>Nx Variable: foo<\/div>/);
});
});

View File

@ -58,6 +58,8 @@ export interface WebBuildBuilderOptions extends BuildBuilderOptions {
buildLibsFromSource?: boolean;
deleteOutputPath?: boolean;
generateIndexHtml?: boolean;
}
function getWebpackConfigs(
@ -186,7 +188,7 @@ export function run(options: WebBuildBuilderOptions, context: ExecutorContext) {
result1 && !result1.hasErrors() && (!result2 || !result2.hasErrors());
const emittedFiles1 = getEmittedFiles(result1);
const emittedFiles2 = result2 ? getEmittedFiles(result2) : [];
if (options.optimization) {
if (options.generateIndexHtml) {
await writeIndexHtml({
crossOrigin: options.crossOrigin,
outputPath: join(options.outputPath, basename(options.index)),

View File

@ -253,6 +253,11 @@
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately.",
"default": true
},
"generateIndexHtml": {
"type": "boolean",
"description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`",
"default": true
}
},
"required": ["tsConfig", "main", "index"],