@@ -15,6 +15,16 @@ const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
1515
1616export function getBrowserConfig ( wco : WebpackConfigOptions ) : webpack . Configuration {
1717 const { buildOptions } = wco ;
18+ const {
19+ crossOrigin = 'none' ,
20+ subresourceIntegrity,
21+ evalSourceMap,
22+ extractLicenses,
23+ vendorChunk,
24+ commonChunk,
25+ styles,
26+ } = buildOptions ;
27+
1828 const extraPlugins = [ ] ;
1929
2030 let isEval = false ;
@@ -27,27 +37,27 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
2737
2838 // See https://webpack.js.org/configuration/devtool/ for sourcemap types.
2939 if ( ( stylesSourceMap || scriptsSourceMap ) &&
30- buildOptions . evalSourceMap &&
40+ evalSourceMap &&
3141 ! stylesOptimization &&
3242 ! scriptsOptimization ) {
3343 // Produce eval sourcemaps for development with serve, which are faster.
3444 isEval = true ;
3545 }
3646
37- if ( buildOptions . subresourceIntegrity ) {
47+ if ( subresourceIntegrity ) {
3848 extraPlugins . push ( new SubresourceIntegrityPlugin ( {
3949 hashFuncNames : [ 'sha384' ] ,
4050 } ) ) ;
4151 }
4252
43- if ( buildOptions . extractLicenses ) {
53+ if ( extractLicenses ) {
4454 extraPlugins . push ( new LicenseWebpackPlugin ( {
4555 stats : {
4656 warnings : false ,
4757 errors : false ,
4858 } ,
4959 perChunkOutput : false ,
50- outputFilename : ` 3rdpartylicenses.txt` ,
60+ outputFilename : ' 3rdpartylicenses.txt' ,
5161 } ) ) ;
5262 }
5363
@@ -59,9 +69,16 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
5969 ) ) ;
6070 }
6171
62- const globalStylesBundleNames = normalizeExtraEntryPoints ( buildOptions . styles , 'styles' )
72+ const globalStylesBundleNames = normalizeExtraEntryPoints ( styles , 'styles' )
6373 . map ( style => style . bundleName ) ;
6474
75+ let crossOriginLoading : string | false = false ;
76+ if ( subresourceIntegrity && crossOrigin === 'none' ) {
77+ crossOriginLoading = 'anonymous' ;
78+ } else if ( crossOrigin !== 'none' ) {
79+ crossOriginLoading = crossOrigin ;
80+ }
81+
6582 return {
6683 devtool : isEval ? 'eval' : false ,
6784 resolve : {
@@ -71,27 +88,27 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
7188 ] ,
7289 } ,
7390 output : {
74- crossOriginLoading : buildOptions . subresourceIntegrity ? 'anonymous' : false ,
91+ crossOriginLoading,
7592 } ,
7693 optimization : {
7794 runtimeChunk : 'single' ,
7895 splitChunks : {
7996 maxAsyncRequests : Infinity ,
8097 cacheGroups : {
81- default : ! ! buildOptions . commonChunk && {
98+ default : ! ! commonChunk && {
8299 chunks : 'async' ,
83100 minChunks : 2 ,
84101 priority : 10 ,
85102 } ,
86- common : ! ! buildOptions . commonChunk && {
103+ common : ! ! commonChunk && {
87104 name : 'common' ,
88105 chunks : 'async' ,
89106 minChunks : 2 ,
90107 enforce : true ,
91108 priority : 5 ,
92109 } ,
93110 vendors : false ,
94- vendor : ! ! buildOptions . vendorChunk && {
111+ vendor : ! ! vendorChunk && {
95112 name : 'vendor' ,
96113 chunks : 'initial' ,
97114 enforce : true ,
0 commit comments