File tree Expand file tree Collapse file tree
packages/angular_devkit/build_webpack/src/webpack Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments