@@ -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,9 +580,20 @@ 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
- // only present for webpack 4.23.0+, assume true otherwise
585
- const watchMode = compiler . watchMode === undefined ? true : compiler . watchMode ;
585
+ // cleanup if not watching
586
+ compiler . hooks . thisCompilation . tap ( 'angular-compiler' , compilation => {
587
+ compilation . hooks . finishModules . tap ( 'angular-compiler' , ( ) => {
588
+ // only present for webpack 4.23.0+, assume true otherwise
589
+ const watchMode = compiler . watchMode === undefined ? true : compiler . watchMode ;
590
+ if ( ! watchMode ) {
591
+ this . _program = null ;
592
+ this . _transformers = [ ] ;
593
+ this . _resourceLoader = undefined ;
594
+ }
595
+ } ) ;
596
+ } ) ;
586
597
587
598
// Decorate inputFileSystem to serve contents of CompilerHost.
588
599
// Use decorated inputFileSystem in watchFileSystem.
@@ -622,6 +633,9 @@ export class AngularCompilerPlugin {
622
633
}
623
634
}
624
635
636
+ // only present for webpack 4.23.0+, assume true otherwise
637
+ const watchMode = compiler . watchMode === undefined ? true : compiler . watchMode ;
638
+
625
639
// Create the webpack compiler host.
626
640
const webpackCompilerHost = new WebpackCompilerHost (
627
641
this . _compilerOptions ,
@@ -631,9 +645,11 @@ export class AngularCompilerPlugin {
631
645
this . _options . directTemplateLoading ,
632
646
) ;
633
647
634
- // Create and set a new WebpackResourceLoader.
635
- this . _resourceLoader = new WebpackResourceLoader ( ) ;
636
- webpackCompilerHost . setResourceLoader ( this . _resourceLoader ) ;
648
+ // Create and set a new WebpackResourceLoader in AOT
649
+ if ( ! this . _JitMode ) {
650
+ this . _resourceLoader = new WebpackResourceLoader ( ) ;
651
+ webpackCompilerHost . setResourceLoader ( this . _resourceLoader ) ;
652
+ }
637
653
638
654
// Use the WebpackCompilerHost with a resource loader to create an AngularCompilerHost.
639
655
this . _compilerHost = createCompilerHost ( {
@@ -787,7 +803,9 @@ export class AngularCompilerPlugin {
787
803
( compilation as any ) . _ngToolsWebpackPluginInstance = this ;
788
804
789
805
// Update the resource loader with the new webpack compilation.
790
- this . _resourceLoader . update ( compilation ) ;
806
+ if ( this . _resourceLoader ) {
807
+ this . _resourceLoader . update ( compilation ) ;
808
+ }
791
809
792
810
try {
793
811
await this . _update ( ) ;
@@ -1012,6 +1030,10 @@ export class AngularCompilerPlugin {
1012
1030
}
1013
1031
1014
1032
getResourceDependencies ( fileName : string ) : string [ ] {
1033
+ if ( ! this . _resourceLoader ) {
1034
+ return [ ] ;
1035
+ }
1036
+
1015
1037
return this . _resourceLoader . getResourceDependencies ( fileName ) ;
1016
1038
}
1017
1039
0 commit comments