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