Skip to content

Commit ffc72cb

Browse files
committed
fix(@angular-devkit/build-angular): update webpack to version 5.104.1
This fixes a performance regression. See: #31350 (comment)
1 parent 4963d9c commit ffc72cb

File tree

7 files changed

+126
-70
lines changed

7 files changed

+126
-70
lines changed

goldens/public-api/angular_devkit/build_webpack/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import { BuilderContext } from '@angular-devkit/architect';
88
import { BuilderOutput } from '@angular-devkit/architect';
99
import { Observable } from 'rxjs';
10-
import webpack from 'webpack';
11-
import WebpackDevServer from 'webpack-dev-server';
10+
import type webpack from 'webpack';
11+
import type WebpackDevServer from 'webpack-dev-server';
1212

1313
// @public (undocumented)
1414
export type BuildResult = BuilderOutput & {

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"terser": "5.43.1",
5656
"tree-kill": "1.2.2",
5757
"tslib": "2.8.1",
58-
"webpack": "5.101.2",
58+
"webpack": "5.104.1",
5959
"webpack-dev-middleware": "7.4.2",
6060
"webpack-dev-server": "5.2.2",
6161
"webpack-merge": "6.0.1",

packages/angular_devkit/build_webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"devDependencies": {
2323
"@angular-devkit/core": "workspace:0.0.0-PLACEHOLDER",
2424
"@ngtools/webpack": "workspace:0.0.0-PLACEHOLDER",
25-
"webpack": "5.101.2",
25+
"webpack": "5.104.1",
2626
"webpack-dev-server": "5.2.2"
2727
},
2828
"peerDependencies": {

packages/angular_devkit/build_webpack/src/builders/webpack-dev-server/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Builder, BuilderContext, createBuilder } from '@angular-devkit/architec
1010
import assert from 'node:assert';
1111
import { resolve as pathResolve } from 'node:path';
1212
import { Observable, from, isObservable, of, switchMap } from 'rxjs';
13-
import webpack from 'webpack';
14-
import WebpackDevServer from 'webpack-dev-server';
13+
import type webpack from 'webpack';
14+
import type WebpackDevServer from 'webpack-dev-server';
1515
import { getEmittedFiles, getWebpackConfig } from '../../utils';
1616
import { BuildResult, WebpackFactory, WebpackLoggingCallback } from '../webpack';
1717
import { Schema as WebpackDevServerBuilderSchema } from './schema';
@@ -44,7 +44,7 @@ export function runWebpackDevServer(
4444
return of(result);
4545
}
4646
} else {
47-
return of(webpack(c));
47+
return from(import('webpack').then((mod) => mod.default(c)));
4848
}
4949
};
5050

@@ -54,9 +54,9 @@ export function runWebpackDevServer(
5454
) => {
5555
if (options.webpackDevServerFactory) {
5656
return new options.webpackDevServerFactory(config, webpack);
57+
} else {
58+
return from(import('webpack-dev-server').then((mod) => new mod.default(config, webpack)));
5759
}
58-
59-
return new WebpackDevServer(config, webpack);
6060
};
6161

6262
const {
@@ -70,16 +70,21 @@ export function runWebpackDevServer(
7070
} = options;
7171

7272
return createWebpack({ ...config, watch: false }).pipe(
73+
switchMap(async (webpackCompiler) => {
74+
return [
75+
webpackCompiler,
76+
options.webpackDevServerFactory ?? (await import('webpack-dev-server')).default,
77+
] as unknown as [webpack.Compiler | null, WebpackDevServerFactory];
78+
}),
7379
switchMap(
74-
(webpackCompiler) =>
80+
([webpackCompiler, webpackDevServerFactory]) =>
7581
new Observable<DevServerBuildOutput>((obs) => {
7682
assert(webpackCompiler, 'Webpack compiler factory did not return a compiler instance.');
7783

7884
const devServerConfig = options.devServerConfig || config.devServer || {};
7985
devServerConfig.host ??= 'localhost';
8086

8187
let result: Partial<DevServerBuildOutput>;
82-
8388
const statsOptions = typeof config.stats === 'boolean' ? undefined : config.stats;
8489

8590
webpackCompiler.hooks.done.tap('build-webpack', (stats) => {
@@ -94,7 +99,7 @@ export function runWebpackDevServer(
9499
} as unknown as DevServerBuildOutput);
95100
});
96101

97-
const devServer = createWebpackDevServer(webpackCompiler, devServerConfig);
102+
const devServer = new webpackDevServerFactory(devServerConfig, webpackCompiler);
98103
devServer.startCallback((err) => {
99104
if (err) {
100105
obs.error(err);

packages/angular_devkit/build_webpack/src/builders/webpack/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Builder, BuilderContext, BuilderOutput, createBuilder } from '@angular-
1010
import assert from 'node:assert';
1111
import { resolve as pathResolve } from 'node:path';
1212
import { Observable, from, isObservable, of, switchMap } from 'rxjs';
13-
import webpack from 'webpack';
13+
import type webpack from 'webpack';
1414
import { EmittedFiles, getEmittedFiles, getWebpackConfig } from '../../utils';
1515
import { Schema as RealWebpackBuilderSchema } from './schema';
1616

@@ -57,7 +57,7 @@ export function runWebpack(
5757
return of(result);
5858
}
5959
} else {
60-
return of(webpack(c));
60+
return from(import('webpack').then((mod) => mod.default(c)));
6161
}
6262
};
6363

@@ -104,7 +104,7 @@ export function runWebpack(
104104

105105
// Teardown logic. Close the watcher when unsubscribed from.
106106
return () => {
107-
watching.close(() => {});
107+
watching?.close(() => {});
108108
webpackCompiler.close(() => {});
109109
};
110110
} else {

packages/ngtools/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
"@angular/compiler": "20.3.7",
3131
"@angular/compiler-cli": "20.3.7",
3232
"typescript": "5.9.2",
33-
"webpack": "5.101.2"
33+
"webpack": "5.104.1"
3434
}
3535
}

0 commit comments

Comments
 (0)