Skip to content

Commit 98ba784

Browse files
committed
refactor(@angular-devkit/build-angular): simplify Webpack split chunks configuration
By leveraging the chunks function filter option, the test option can be reduced to only a regular expression instead of the more complex function. This change also provides support for Webpack 5.
1 parent 1269190 commit 98ba784

File tree

2 files changed

+9
-23
lines changed
  • packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs

2 files changed

+9
-23
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/browser.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import * as webpack from 'webpack';
99
import { CommonJsUsageWarnPlugin } from '../../plugins/webpack';
1010
import { WebpackConfigOptions } from '../build-options';
11-
import { getSourceMapDevTool, isPolyfillsEntry, normalizeExtraEntryPoints } from './utils';
11+
import { getSourceMapDevTool } from './utils';
1212

1313
export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configuration {
1414
const { buildOptions } = wco;
@@ -18,7 +18,6 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
1818
extractLicenses,
1919
vendorChunk,
2020
commonChunk,
21-
styles,
2221
allowedCommonJsDependencies,
2322
} = buildOptions;
2423

@@ -57,9 +56,6 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
5756
));
5857
}
5958

60-
const globalStylesBundleNames = normalizeExtraEntryPoints(styles, 'styles')
61-
.map(style => style.bundleName);
62-
6359
let crossOriginLoading: 'anonymous' | 'use-credentials' | false = false;
6460
if (subresourceIntegrity && crossOrigin === 'none') {
6561
crossOriginLoading = 'anonymous';
@@ -93,17 +89,11 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
9389
priority: 5,
9490
},
9591
vendors: false,
96-
vendor: !!vendorChunk && {
92+
defaultVendors: !!vendorChunk && {
9793
name: 'vendor',
98-
chunks: 'initial',
94+
chunks: (chunk) => chunk.name === 'main',
9995
enforce: true,
100-
test: (module: { nameForCondition?: Function }, chunks: Array<{ name: string }>) => {
101-
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
102-
103-
return /[\\/]node_modules[\\/]/.test(moduleName)
104-
&& !chunks.some(({ name }) => isPolyfillsEntry(name)
105-
|| globalStylesBundleNames.includes(name));
106-
},
96+
test: /[\\/]node_modules[\\/]/,
10797
},
10898
},
10999
},

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,14 @@ export function getTestConfig(
7474
plugins: extraPlugins,
7575
optimization: {
7676
splitChunks: {
77-
chunks: ((chunk: { name: string }) => !isPolyfillsEntry(chunk.name)),
77+
chunks: (chunk) => !isPolyfillsEntry(chunk.name),
7878
cacheGroups: {
7979
vendors: false,
80-
vendor: {
80+
defaultVendors: {
8181
name: 'vendor',
82-
chunks: 'initial',
83-
test: (module: { nameForCondition?: () => string }, chunks: { name: string }[]) => {
84-
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
85-
86-
return /[\\/]node_modules[\\/]/.test(moduleName)
87-
&& !chunks.some(({ name }) => isPolyfillsEntry(name));
88-
},
82+
chunks: (chunk) => chunk.name === 'main',
83+
enforce: true,
84+
test: /[\\/]node_modules[\\/]/,
8985
},
9086
},
9187
},

0 commit comments

Comments
 (0)