1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.getBrowserConfig = void 0;
|
---|
11 | const utils_1 = require("../../utils");
|
---|
12 | const plugins_1 = require("../plugins");
|
---|
13 | const helpers_1 = require("../utils/helpers");
|
---|
14 | function getBrowserConfig(wco) {
|
---|
15 | const { buildOptions } = wco;
|
---|
16 | const { crossOrigin = 'none', subresourceIntegrity, extractLicenses, vendorChunk, commonChunk, allowedCommonJsDependencies, } = buildOptions;
|
---|
17 | const extraPlugins = [];
|
---|
18 | const { styles: stylesSourceMap, scripts: scriptsSourceMap, hidden: hiddenSourceMap, } = buildOptions.sourceMap;
|
---|
19 | if (subresourceIntegrity) {
|
---|
20 | const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
|
---|
21 | extraPlugins.push(new SubresourceIntegrityPlugin({
|
---|
22 | hashFuncNames: ['sha384'],
|
---|
23 | }));
|
---|
24 | }
|
---|
25 | if (scriptsSourceMap || stylesSourceMap) {
|
---|
26 | extraPlugins.push(helpers_1.getSourceMapDevTool(scriptsSourceMap, stylesSourceMap, buildOptions.differentialLoadingNeeded && !buildOptions.watch ? true : hiddenSourceMap, false));
|
---|
27 | }
|
---|
28 | let crossOriginLoading = false;
|
---|
29 | if (subresourceIntegrity && crossOrigin === 'none') {
|
---|
30 | crossOriginLoading = 'anonymous';
|
---|
31 | }
|
---|
32 | else if (crossOrigin !== 'none') {
|
---|
33 | crossOriginLoading = crossOrigin;
|
---|
34 | }
|
---|
35 | const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(wco.projectRoot);
|
---|
36 | return {
|
---|
37 | devtool: false,
|
---|
38 | resolve: {
|
---|
39 | mainFields: ['es2015', 'browser', 'module', 'main'],
|
---|
40 | },
|
---|
41 | output: {
|
---|
42 | crossOriginLoading,
|
---|
43 | trustedTypes: 'angular#bundler',
|
---|
44 | },
|
---|
45 | optimization: {
|
---|
46 | runtimeChunk: 'single',
|
---|
47 | splitChunks: {
|
---|
48 | maxAsyncRequests: Infinity,
|
---|
49 | cacheGroups: {
|
---|
50 | default: !!commonChunk && {
|
---|
51 | chunks: 'async',
|
---|
52 | minChunks: 2,
|
---|
53 | priority: 10,
|
---|
54 | },
|
---|
55 | common: !!commonChunk && {
|
---|
56 | name: 'common',
|
---|
57 | chunks: 'async',
|
---|
58 | minChunks: 2,
|
---|
59 | enforce: true,
|
---|
60 | priority: 5,
|
---|
61 | },
|
---|
62 | vendors: false,
|
---|
63 | defaultVendors: !!vendorChunk && {
|
---|
64 | name: 'vendor',
|
---|
65 | chunks: (chunk) => chunk.name === 'main',
|
---|
66 | enforce: true,
|
---|
67 | test: /[\\/]node_modules[\\/]/,
|
---|
68 | },
|
---|
69 | },
|
---|
70 | },
|
---|
71 | },
|
---|
72 | plugins: [
|
---|
73 | new plugins_1.CommonJsUsageWarnPlugin({
|
---|
74 | allowedDependencies: allowedCommonJsDependencies,
|
---|
75 | }),
|
---|
76 | ...extraPlugins,
|
---|
77 | ],
|
---|
78 | node: false,
|
---|
79 | };
|
---|
80 | }
|
---|
81 | exports.getBrowserConfig = getBrowserConfig;
|
---|