From 283fcc268b2ea87d4c29420a288b2418e5704fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Gre=C5=A1ak?= Date: Mon, 23 Aug 2021 12:24:36 +0200 Subject: [PATCH] cleanup(web): use same test function for webpack 4 and 5 This is a bit less verbose than the previous version. --- .../models/webpack-configs/browser.ts | 60 +++++++------------ 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/packages/web/src/utils/third-party/cli-files/models/webpack-configs/browser.ts b/packages/web/src/utils/third-party/cli-files/models/webpack-configs/browser.ts index c5f9e1c794187..6536ff53800c7 100644 --- a/packages/web/src/utils/third-party/cli-files/models/webpack-configs/browser.ts +++ b/packages/web/src/utils/third-party/cli-files/models/webpack-configs/browser.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ // TODO: import from 'webpack' in Nx 13 -import type { Module, ModuleGraph, ChunkGraph } from 'webpack-5'; +import type { Module, ModuleGraph, ChunkGraph, Chunk } from 'webpack-5'; import { LicenseWebpackPlugin } from 'license-webpack-plugin'; import { WebpackConfigOptions, BuildOptions } from '../build-options'; import { @@ -126,44 +126,28 @@ export function getBrowserConfig(wco: WebpackConfigOptions) { name: 'vendor', chunks: isWebpack5 ? (chunk) => chunk.name === 'main' : 'initial', enforce: true, - test: isWebpack5 - ? ( - module: Module, - // `CacheGroupsContext`, but it's not exported from webpack types - context: { moduleGraph: ModuleGraph; chunkGraph: ChunkGraph } - ) => { - const moduleName = module.nameForCondition - ? module.nameForCondition() - : ''; - const chunks = context.chunkGraph.getModuleChunks(module); + test: ( + module: Module, + // `CacheGroupsContext`, but it's not exported from webpack types + context: { moduleGraph: ModuleGraph; chunkGraph: ChunkGraph } + ) => { + const moduleName = module.nameForCondition + ? module.nameForCondition() + : ''; + // TODO(jack): Remove in Nx 13 + const chunks = isWebpack5 + ? context.chunkGraph.getModuleChunks(module) + : (context as unknown as Chunk[]); - return ( - /[\\/]node_modules[\\/]/.test(moduleName) && - !chunks.some( - ({ name }) => - isPolyfillsEntry(name) || - globalStylesBundleNames.includes(name) - ) - ); - } - : // TODO(jack): Remove in Nx 13 - ( - module: { nameForCondition?: Function }, - chunks: Array<{ name: string }> - ) => { - const moduleName = module.nameForCondition - ? module.nameForCondition() - : ''; - - return ( - /[\\/]node_modules[\\/]/.test(moduleName) && - !chunks.some( - ({ name }) => - isPolyfillsEntry(name) || - globalStylesBundleNames.includes(name) - ) - ); - }, + return ( + /[\\/]node_modules[\\/]/.test(moduleName) && + !chunks.some( + ({ name }) => + isPolyfillsEntry(name) || + globalStylesBundleNames.includes(name) + ) + ); + }, }, }, },