@@ -133,7 +133,7 @@ export class AngularCompilerPlugin {
133
133
private _program : ( ts . Program | Program ) | null ;
134
134
private _compilerHost : WebpackCompilerHost & CompilerHost ;
135
135
private _moduleResolutionCache : ts . ModuleResolutionCache ;
136
- private _resourceLoader : WebpackResourceLoader ;
136
+ private _resourceLoader ? : WebpackResourceLoader ;
137
137
// Contains `moduleImportPath#exportName` => `fullModulePath`.
138
138
private _lazyRoutes : LazyRouteMap = Object . create ( null ) ;
139
139
private _tsConfigPath : string ;
@@ -579,9 +579,20 @@ export class AngularCompilerPlugin {
579
579
}
580
580
581
581
// Registration hook for webpack plugin.
582
+ // tslint:disable-next-line:no-big-function
582
583
apply ( compiler : Compiler & { watchMode ?: boolean } ) {
583
- // only present for webpack 4.23.0+, assume true otherwise
584
- const watchMode = compiler . watchMode === undefined ? true : compiler . watchMode ;
584
+ // cleanup if not watching
585
+ compiler . hooks . thisCompilation . tap ( 'angular-compiler' , compilation => {
586
+ compilation . hooks . finishModules . tap ( 'angular-compiler' , ( ) => {
587
+ // only present for webpack 4.23.0+, assume true otherwise
588
+ const watchMode = compiler . watchMode === undefined ? true : compiler . watchMode ;
589
+ if ( ! watchMode ) {
590
+ this . _program = null ;
591
+ this . _transformers = [ ] ;
592
+ this . _resourceLoader = undefined ;
593
+ }
594
+ } ) ;
595
+ } ) ;
585
596
586
597
// Decorate inputFileSystem to serve contents of CompilerHost.
587
598
// Use decorated inputFileSystem in watchFileSystem.
@@ -621,6 +632,9 @@ export class AngularCompilerPlugin {
621
632
}
622
633
}
623
634
635
+ // only present for webpack 4.23.0+, assume true otherwise
636
+ const watchMode = compiler . watchMode === undefined ? true : compiler . watchMode ;
637
+
624
638
// Create the webpack compiler host.
625
639
const webpackCompilerHost = new WebpackCompilerHost (
626
640
this . _compilerOptions ,
@@ -629,9 +643,11 @@ export class AngularCompilerPlugin {
629
643
watchMode ,
630
644
) ;
631
645
632
- // Create and set a new WebpackResourceLoader.
633
- this . _resourceLoader = new WebpackResourceLoader ( ) ;
634
- webpackCompilerHost . setResourceLoader ( this . _resourceLoader ) ;
646
+ // Create and set a new WebpackResourceLoader in AOT
647
+ if ( ! this . _JitMode ) {
648
+ this . _resourceLoader = new WebpackResourceLoader ( ) ;
649
+ webpackCompilerHost . setResourceLoader ( this . _resourceLoader ) ;
650
+ }
635
651
636
652
// Use the WebpackCompilerHost with a resource loader to create an AngularCompilerHost.
637
653
this . _compilerHost = createCompilerHost ( {
@@ -785,7 +801,9 @@ export class AngularCompilerPlugin {
785
801
( compilation as any ) . _ngToolsWebpackPluginInstance = this ;
786
802
787
803
// Update the resource loader with the new webpack compilation.
788
- this . _resourceLoader . update ( compilation ) ;
804
+ if ( this . _resourceLoader ) {
805
+ this . _resourceLoader . update ( compilation ) ;
806
+ }
789
807
790
808
try {
791
809
await this . _update ( ) ;
@@ -1010,6 +1028,10 @@ export class AngularCompilerPlugin {
1010
1028
}
1011
1029
1012
1030
getResourceDependencies ( fileName : string ) : string [ ] {
1031
+ if ( ! this . _resourceLoader ) {
1032
+ return [ ] ;
1033
+ }
1034
+
1013
1035
return this . _resourceLoader . getResourceDependencies ( fileName ) ;
1014
1036
}
1015
1037
0 commit comments