[6a3a178] | 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'],
|
---|
[e29cc2e] | 40 | conditionNames: ['es2015', '...'],
|
---|
[6a3a178] | 41 | },
|
---|
| 42 | output: {
|
---|
| 43 | crossOriginLoading,
|
---|
| 44 | trustedTypes: 'angular#bundler',
|
---|
| 45 | },
|
---|
| 46 | optimization: {
|
---|
| 47 | runtimeChunk: 'single',
|
---|
| 48 | splitChunks: {
|
---|
| 49 | maxAsyncRequests: Infinity,
|
---|
| 50 | cacheGroups: {
|
---|
| 51 | default: !!commonChunk && {
|
---|
| 52 | chunks: 'async',
|
---|
| 53 | minChunks: 2,
|
---|
| 54 | priority: 10,
|
---|
| 55 | },
|
---|
| 56 | common: !!commonChunk && {
|
---|
| 57 | name: 'common',
|
---|
| 58 | chunks: 'async',
|
---|
| 59 | minChunks: 2,
|
---|
| 60 | enforce: true,
|
---|
| 61 | priority: 5,
|
---|
| 62 | },
|
---|
| 63 | vendors: false,
|
---|
| 64 | defaultVendors: !!vendorChunk && {
|
---|
| 65 | name: 'vendor',
|
---|
| 66 | chunks: (chunk) => chunk.name === 'main',
|
---|
| 67 | enforce: true,
|
---|
| 68 | test: /[\\/]node_modules[\\/]/,
|
---|
| 69 | },
|
---|
| 70 | },
|
---|
| 71 | },
|
---|
| 72 | },
|
---|
| 73 | plugins: [
|
---|
| 74 | new plugins_1.CommonJsUsageWarnPlugin({
|
---|
| 75 | allowedDependencies: allowedCommonJsDependencies,
|
---|
| 76 | }),
|
---|
| 77 | ...extraPlugins,
|
---|
| 78 | ],
|
---|
| 79 | node: false,
|
---|
| 80 | };
|
---|
| 81 | }
|
---|
| 82 | exports.getBrowserConfig = getBrowserConfig;
|
---|