-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathbrowser.ts
109 lines (101 loc) · 2.83 KB
/
browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as webpack from 'webpack';
import { CommonJsUsageWarnPlugin } from '../../plugins/webpack';
import { WebpackConfigOptions } from '../build-options';
import { getSourceMapDevTool } from './utils';
export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configuration {
const { buildOptions } = wco;
const {
crossOrigin = 'none',
subresourceIntegrity,
extractLicenses,
vendorChunk,
commonChunk,
allowedCommonJsDependencies,
} = buildOptions;
const extraPlugins = [];
const {
styles: stylesSourceMap,
scripts: scriptsSourceMap,
hidden: hiddenSourceMap,
} = buildOptions.sourceMap;
if (subresourceIntegrity) {
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
extraPlugins.push(new SubresourceIntegrityPlugin({
hashFuncNames: ['sha384'],
}));
}
if (extractLicenses) {
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
extraPlugins.push(new LicenseWebpackPlugin({
stats: {
warnings: false,
errors: false,
},
perChunkOutput: false,
outputFilename: '3rdpartylicenses.txt',
}));
}
if (scriptsSourceMap || stylesSourceMap) {
extraPlugins.push(getSourceMapDevTool(
scriptsSourceMap,
stylesSourceMap,
wco.differentialLoadingMode ? true : hiddenSourceMap,
));
}
let crossOriginLoading: 'anonymous' | 'use-credentials' | false = false;
if (subresourceIntegrity && crossOrigin === 'none') {
crossOriginLoading = 'anonymous';
} else if (crossOrigin !== 'none') {
crossOriginLoading = crossOrigin;
}
return {
devtool: false,
resolve: {
mainFields: ['es2015', 'browser', 'module', 'main'],
},
output: {
crossOriginLoading,
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
maxAsyncRequests: Infinity,
cacheGroups: {
default: !!commonChunk && {
chunks: 'async',
minChunks: 2,
priority: 10,
},
common: !!commonChunk && {
name: 'common',
chunks: 'async',
minChunks: 2,
enforce: true,
priority: 5,
},
vendors: false,
defaultVendors: !!vendorChunk && {
name: 'vendor',
chunks: (chunk) => chunk.name === 'main',
enforce: true,
test: /[\\/]node_modules[\\/]/,
},
},
},
},
plugins: [
new CommonJsUsageWarnPlugin({
allowedDepedencies: allowedCommonJsDependencies,
}),
...extraPlugins,
],
node: false,
};
}