diff --git a/packages/cli/src/lib/bundler/optimization.ts b/packages/cli/src/lib/bundler/optimization.ts index b8164d263d..254799f78c 100644 --- a/packages/cli/src/lib/bundler/optimization.ts +++ b/packages/cli/src/lib/bundler/optimization.ts @@ -26,7 +26,7 @@ export const optimization = ( return { minimize: !isDev, - // Only configure when parallel is explicitly overriden from the default + // Only configure when parallel is explicitly overridden from the default ...(!isParallelDefault(options.parallel) ? { minimizer: [ @@ -45,11 +45,15 @@ export const optimization = ( // enough, if they're smaller they end up in the main packages: { chunks: 'initial', - test: /[\\/]node_modules[\\/]/, + test(module: any) { + return Boolean( + module?.resource?.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/), + ); + }, name(module: any) { // get the name. E.g. node_modules/packageName/not/this/part.js // or node_modules/packageName - const packageName = module.context.match( + const packageName = module.resource.match( /[\\/]node_modules[\\/](.*?)([\\/]|$)/, )[1];