@@ -15,6 +15,16 @@ const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
15
15
16
16
export function getBrowserConfig ( wco : WebpackConfigOptions ) : webpack . Configuration {
17
17
const { buildOptions } = wco ;
18
+ const {
19
+ crossOrigin = 'none' ,
20
+ subresourceIntegrity,
21
+ evalSourceMap,
22
+ extractLicenses,
23
+ vendorChunk,
24
+ commonChunk,
25
+ styles,
26
+ } = buildOptions ;
27
+
18
28
const extraPlugins = [ ] ;
19
29
20
30
let isEval = false ;
@@ -27,27 +37,27 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
27
37
28
38
// See https://webpack.js.org/configuration/devtool/ for sourcemap types.
29
39
if ( ( stylesSourceMap || scriptsSourceMap ) &&
30
- buildOptions . evalSourceMap &&
40
+ evalSourceMap &&
31
41
! stylesOptimization &&
32
42
! scriptsOptimization ) {
33
43
// Produce eval sourcemaps for development with serve, which are faster.
34
44
isEval = true ;
35
45
}
36
46
37
- if ( buildOptions . subresourceIntegrity ) {
47
+ if ( subresourceIntegrity ) {
38
48
extraPlugins . push ( new SubresourceIntegrityPlugin ( {
39
49
hashFuncNames : [ 'sha384' ] ,
40
50
} ) ) ;
41
51
}
42
52
43
- if ( buildOptions . extractLicenses ) {
53
+ if ( extractLicenses ) {
44
54
extraPlugins . push ( new LicenseWebpackPlugin ( {
45
55
stats : {
46
56
warnings : false ,
47
57
errors : false ,
48
58
} ,
49
59
perChunkOutput : false ,
50
- outputFilename : ` 3rdpartylicenses.txt` ,
60
+ outputFilename : ' 3rdpartylicenses.txt' ,
51
61
} ) ) ;
52
62
}
53
63
@@ -59,9 +69,16 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
59
69
) ) ;
60
70
}
61
71
62
- const globalStylesBundleNames = normalizeExtraEntryPoints ( buildOptions . styles , 'styles' )
72
+ const globalStylesBundleNames = normalizeExtraEntryPoints ( styles , 'styles' )
63
73
. map ( style => style . bundleName ) ;
64
74
75
+ let crossOriginLoading : string | false = false ;
76
+ if ( subresourceIntegrity && crossOrigin === 'none' ) {
77
+ crossOriginLoading = 'anonymous' ;
78
+ } else if ( crossOrigin !== 'none' ) {
79
+ crossOriginLoading = crossOrigin ;
80
+ }
81
+
65
82
return {
66
83
devtool : isEval ? 'eval' : false ,
67
84
resolve : {
@@ -71,27 +88,27 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
71
88
] ,
72
89
} ,
73
90
output : {
74
- crossOriginLoading : buildOptions . subresourceIntegrity ? 'anonymous' : false ,
91
+ crossOriginLoading,
75
92
} ,
76
93
optimization : {
77
94
runtimeChunk : 'single' ,
78
95
splitChunks : {
79
96
maxAsyncRequests : Infinity ,
80
97
cacheGroups : {
81
- default : ! ! buildOptions . commonChunk && {
98
+ default : ! ! commonChunk && {
82
99
chunks : 'async' ,
83
100
minChunks : 2 ,
84
101
priority : 10 ,
85
102
} ,
86
- common : ! ! buildOptions . commonChunk && {
103
+ common : ! ! commonChunk && {
87
104
name : 'common' ,
88
105
chunks : 'async' ,
89
106
minChunks : 2 ,
90
107
enforce : true ,
91
108
priority : 5 ,
92
109
} ,
93
110
vendors : false ,
94
- vendor : ! ! buildOptions . vendorChunk && {
111
+ vendor : ! ! vendorChunk && {
95
112
name : 'vendor' ,
96
113
chunks : 'initial' ,
97
114
enforce : true ,
0 commit comments