@@ -165,6 +165,10 @@ export class AotPlugin implements Tapable {
165
165
this . _program = ts . createProgram (
166
166
this . _rootFilePath , this . _compilerOptions , this . _compilerHost ) ;
167
167
168
+ // We enable caching of the filesystem in compilerHost _after_ the program has been created,
169
+ // because we don't want SourceFile instances to be cached past this point.
170
+ this . _compilerHost . enableCaching ( ) ;
171
+
168
172
if ( options . entryModule ) {
169
173
this . _entryModule = options . entryModule ;
170
174
} else if ( ( tsConfig . raw [ 'angularCompilerOptions' ] as any )
@@ -194,6 +198,10 @@ export class AotPlugin implements Tapable {
194
198
apply ( compiler : any ) {
195
199
this . _compiler = compiler ;
196
200
201
+ compiler . plugin ( 'invalid' , ( fileName : string , timestamp : number ) => {
202
+ this . _compilerHost . invalidate ( fileName ) ;
203
+ } ) ;
204
+
197
205
// Add lazy modules to the context module for @angular /core/src/linker
198
206
compiler . plugin ( 'context-module-factory' , ( cmf : any ) => {
199
207
cmf . plugin ( 'after-resolve' , ( result : any , callback : ( err ?: any , request ?: any ) => void ) => {
@@ -251,6 +259,7 @@ export class AotPlugin implements Tapable {
251
259
if ( this . _compilation . _ngToolsWebpackPluginInstance ) {
252
260
return cb ( new Error ( 'An @ngtools/webpack plugin already exist for this compilation.' ) ) ;
253
261
}
262
+
254
263
this . _compilation . _ngToolsWebpackPluginInstance = this ;
255
264
256
265
this . _resourceLoader = new WebpackResourceLoader ( compilation ) ;
@@ -284,18 +293,20 @@ export class AotPlugin implements Tapable {
284
293
this . _rootFilePath , this . _compilerOptions , this . _compilerHost , this . _program ) ;
285
294
} )
286
295
. then ( ( ) => {
287
- const diagnostics = this . _program . getGlobalDiagnostics ( ) ;
288
- if ( diagnostics . length > 0 ) {
289
- const message = diagnostics
290
- . map ( diagnostic => {
291
- const { line, character} = diagnostic . file . getLineAndCharacterOfPosition (
292
- diagnostic . start ) ;
293
- const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
294
- return `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } )` ;
295
- } )
296
- . join ( '\n' ) ;
297
-
298
- throw new Error ( message ) ;
296
+ if ( this . _typeCheck ) {
297
+ const diagnostics = this . _program . getGlobalDiagnostics ( ) ;
298
+ if ( diagnostics . length > 0 ) {
299
+ const message = diagnostics
300
+ . map ( diagnostic => {
301
+ const { line, character} = diagnostic . file . getLineAndCharacterOfPosition (
302
+ diagnostic . start ) ;
303
+ const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
304
+ return `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } )` ;
305
+ } )
306
+ . join ( '\n' ) ;
307
+
308
+ throw new Error ( message ) ;
309
+ }
299
310
}
300
311
} )
301
312
. then ( ( ) => {
0 commit comments