diff --git a/packages/angular_devkit/build_angular/src/utils/build-options.ts b/packages/angular_devkit/build_angular/src/utils/build-options.ts index 70715e8c2b7d..0daf9506bf74 100644 --- a/packages/angular_devkit/build_angular/src/utils/build-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/build-options.ts @@ -17,6 +17,7 @@ import { IndexUnion, InlineStyleLanguage, Localize, + OutputHashing, SourceMapClass, } from '../builders/browser/schema'; import { Schema as DevServerSchema } from '../builders/dev-server/schema'; @@ -42,7 +43,7 @@ export interface BuildOptions { bundleDependencies?: boolean; externalDependencies?: string[]; watch?: boolean; - outputHashing?: string; + outputHashing?: OutputHashing; poll?: number; index?: IndexUnion; deleteOutputPath?: boolean; diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts index 5b5246eaf761..545d877a4c80 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts @@ -98,7 +98,7 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise('@angular/compiler-cli'); // determine hashing format - const hashFormat = getOutputHashFormat(buildOptions.outputHashing || 'none'); + const hashFormat = getOutputHashFormat(buildOptions.outputHashing); if (buildOptions.progress) { extraPlugins.push(new ProgressPlugin(platform)); diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/styles.ts b/packages/angular_devkit/build_angular/src/webpack/configs/styles.ts index 113207908177..742cc7f83993 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/styles.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/styles.ts @@ -83,7 +83,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration { const cssSourceMap = buildOptions.sourceMap.styles; // Determine hashing format. - const hashFormat = getOutputHashFormat(buildOptions.outputHashing as string); + const hashFormat = getOutputHashFormat(buildOptions.outputHashing); // use includePaths from appConfig const includePaths = diff --git a/packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts b/packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts index d8a59c72efb9..9f4cea1b916f 100644 --- a/packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts +++ b/packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts @@ -17,6 +17,7 @@ import { AssetPatternClass, ExtraEntryPoint, ExtraEntryPointClass, + OutputHashing, } from '../../builders/browser/schema'; import { WebpackConfigOptions } from '../../utils/build-options'; import { VERSION } from '../../utils/package-version'; @@ -28,25 +29,40 @@ export interface HashFormat { script: string; } -export function getOutputHashFormat(option: string, length = 20): HashFormat { - const hashFormats: { [option: string]: HashFormat } = { - none: { chunk: '', extract: '', file: '', script: '' }, - media: { chunk: '', extract: '', file: `.[hash:${length}]`, script: '' }, - bundles: { - chunk: `.[contenthash:${length}]`, - extract: `.[contenthash:${length}]`, - file: '', - script: `.[hash:${length}]`, - }, - all: { - chunk: `.[contenthash:${length}]`, - extract: `.[contenthash:${length}]`, - file: `.[hash:${length}]`, - script: `.[hash:${length}]`, - }, - }; - - return hashFormats[option] || hashFormats['none']; +export function getOutputHashFormat(outputHashing = OutputHashing.None, length = 20): HashFormat { + const hashTemplate = `.[contenthash:${length}]`; + + switch (outputHashing) { + case 'media': + return { + chunk: '', + extract: '', + file: hashTemplate, + script: '', + }; + case 'bundles': + return { + chunk: hashTemplate, + extract: hashTemplate, + file: '', + script: hashTemplate, + }; + case 'all': + return { + chunk: hashTemplate, + extract: hashTemplate, + file: hashTemplate, + script: hashTemplate, + }; + case 'none': + default: + return { + chunk: '', + extract: '', + file: '', + script: '', + }; + } } export type NormalizedEntryPoint = Required;