diff --git a/docs/angular/api-web/executors/build.md b/docs/angular/api-web/executors/build.md index a99813e220..7f196c3165 100644 --- a/docs/angular/api-web/executors/build.md +++ b/docs/angular/api-web/executors/build.md @@ -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` diff --git a/docs/node/api-web/executors/build.md b/docs/node/api-web/executors/build.md index c57f5c7e1e..5a4f16f1d7 100644 --- a/docs/node/api-web/executors/build.md +++ b/docs/node/api-web/executors/build.md @@ -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` diff --git a/docs/react/api-web/executors/build.md b/docs/react/api-web/executors/build.md index a4b9f322fa..3088112bcc 100644 --- a/docs/react/api-web/executors/build.md +++ b/docs/react/api-web/executors/build.md @@ -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` diff --git a/e2e/web/src/web.test.ts b/e2e/web/src/web.test.ts index 0db91372e6..7401c11f16 100644 --- a/e2e/web/src/web.test.ts +++ b/e2e/web/src/web.test.ts @@ -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(/
Nx Variable: foo<\/div>/); + expect(resultIndexContents).toMatch(/
Nx Variable: foo<\/div>/); + expect(resultIndexContents).toMatch(/
Nx Variable: foo<\/div>/); }); }); diff --git a/packages/web/src/executors/build/build.impl.ts b/packages/web/src/executors/build/build.impl.ts index 2975f26dc8..25b0e4c836 100644 --- a/packages/web/src/executors/build/build.impl.ts +++ b/packages/web/src/executors/build/build.impl.ts @@ -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)), diff --git a/packages/web/src/executors/build/schema.json b/packages/web/src/executors/build/schema.json index 343f1a7947..0c20789215 100644 --- a/packages/web/src/executors/build/schema.json +++ b/packages/web/src/executors/build/schema.json @@ -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"],