Skip to content

Commit dc3cdae

Browse files
committed
fix(@angular-devkit/build-webpack): fully close Webpack 5 compiler
The Webpack 5 compiler now contains a close function that should be called when the compiler is finished.
1 parent f122b2f commit dc3cdae

File tree

1 file changed

+15
-2
lines changed
  • packages/angular_devkit/build_webpack/src/webpack

1 file changed

+15
-2
lines changed

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export function runWebpack(
5252

5353
return createWebpack({ ...config, watch: false }).pipe(
5454
switchMap(webpackCompiler => new Observable<BuildResult>(obs => {
55+
// Webpack 5 has a compiler level close function
56+
// The close function will crash if caching is disabled
57+
const compilerClose = webpackCompiler.options.cache !== false
58+
? (webpackCompiler as { close?(callback: () => void): void }).close
59+
: undefined;
60+
5561
const callback = (err?: Error, stats?: webpack.Stats) => {
5662
if (err) {
5763
return obs.error(err);
@@ -71,7 +77,11 @@ export function runWebpack(
7177
} as unknown as BuildResult);
7278

7379
if (!config.watch) {
74-
obs.complete();
80+
if (compilerClose) {
81+
compilerClose(() => obs.complete());
82+
} else {
83+
obs.complete();
84+
}
7585
}
7686
};
7787

@@ -81,7 +91,10 @@ export function runWebpack(
8191
const watching = webpackCompiler.watch(watchOptions, callback);
8292

8393
// Teardown logic. Close the watcher when unsubscribed from.
84-
return () => watching.close(() => { });
94+
return () => {
95+
watching.close(() => { });
96+
compilerClose?.(() => { });
97+
};
8598
} else {
8699
webpackCompiler.run(callback);
87100
}

0 commit comments

Comments
 (0)