@@ -13,7 +13,12 @@ import glob from 'glob';
13
13
import * as path from 'path' ;
14
14
import { ScriptTarget } from 'typescript' ;
15
15
import type { Configuration , WebpackOptionsNormalized } from 'webpack' ;
16
- import { AssetPatternClass , ScriptElement , StyleElement } from '../../builders/browser/schema' ;
16
+ import {
17
+ AssetPatternClass ,
18
+ OutputHashing ,
19
+ ScriptElement ,
20
+ StyleElement ,
21
+ } from '../../builders/browser/schema' ;
17
22
import { WebpackConfigOptions } from '../../utils/build-options' ;
18
23
import { VERSION } from '../../utils/package-version' ;
19
24
@@ -24,25 +29,40 @@ export interface HashFormat {
24
29
script : string ;
25
30
}
26
31
27
- export function getOutputHashFormat ( option : string , length = 20 ) : HashFormat {
28
- const hashFormats : { [ option : string ] : HashFormat } = {
29
- none : { chunk : '' , extract : '' , file : '' , script : '' } ,
30
- media : { chunk : '' , extract : '' , file : `.[hash:${ length } ]` , script : '' } ,
31
- bundles : {
32
- chunk : `.[contenthash:${ length } ]` ,
33
- extract : `.[contenthash:${ length } ]` ,
34
- file : '' ,
35
- script : `.[hash:${ length } ]` ,
36
- } ,
37
- all : {
38
- chunk : `.[contenthash:${ length } ]` ,
39
- extract : `.[contenthash:${ length } ]` ,
40
- file : `.[hash:${ length } ]` ,
41
- script : `.[hash:${ length } ]` ,
42
- } ,
43
- } ;
44
-
45
- return hashFormats [ option ] || hashFormats [ 'none' ] ;
32
+ export function getOutputHashFormat ( outputHashing = OutputHashing . None , length = 20 ) : HashFormat {
33
+ const hashTemplate = `.[contenthash:${ length } ]` ;
34
+
35
+ switch ( outputHashing ) {
36
+ case 'media' :
37
+ return {
38
+ chunk : '' ,
39
+ extract : '' ,
40
+ file : hashTemplate ,
41
+ script : '' ,
42
+ } ;
43
+ case 'bundles' :
44
+ return {
45
+ chunk : hashTemplate ,
46
+ extract : hashTemplate ,
47
+ file : '' ,
48
+ script : hashTemplate ,
49
+ } ;
50
+ case 'all' :
51
+ return {
52
+ chunk : hashTemplate ,
53
+ extract : hashTemplate ,
54
+ file : hashTemplate ,
55
+ script : hashTemplate ,
56
+ } ;
57
+ case 'none' :
58
+ default :
59
+ return {
60
+ chunk : '' ,
61
+ extract : '' ,
62
+ file : '' ,
63
+ script : '' ,
64
+ } ;
65
+ }
46
66
}
47
67
48
68
export type NormalizedEntryPoint = Required < Exclude < ScriptElement | StyleElement , string > > ;
0 commit comments