@@ -101,7 +101,6 @@ export class AngularCompilerPlugin implements Tapable {
101
101
private _donePromise : Promise < void > | null ;
102
102
private _compiler : any = null ;
103
103
private _compilation : any = null ;
104
- private _failedCompilation = false ;
105
104
106
105
// TypeChecker process.
107
106
private _forkTypeChecker = true ;
@@ -115,7 +114,6 @@ export class AngularCompilerPlugin implements Tapable {
115
114
116
115
get options ( ) { return this . _options ; }
117
116
get done ( ) { return this . _donePromise ; }
118
- get failedCompilation ( ) { return this . _failedCompilation ; }
119
117
get entryModule ( ) {
120
118
const splitted = this . _entryModule . split ( '#' ) ;
121
119
const path = splitted [ 0 ] ;
@@ -327,13 +325,19 @@ export class AngularCompilerPlugin implements Tapable {
327
325
this . _updateForkedTypeChecker ( changedTsFiles ) ;
328
326
}
329
327
330
- if ( this . _JitMode ) {
328
+ // We want to allow emitting with errors on the first run so that imports can be added
329
+ // to the webpack dependency tree and rebuilds triggered by file edits.
330
+ const compilerOptions = {
331
+ ...this . _angularCompilerOptions ,
332
+ noEmitOnError : ! this . _firstRun
333
+ } ;
331
334
335
+ if ( this . _JitMode ) {
332
336
// Create the TypeScript program.
333
337
time ( 'AngularCompilerPlugin._createOrUpdateProgram.ts.createProgram' ) ;
334
338
this . _program = ts . createProgram (
335
339
this . _tsFilenames ,
336
- this . _angularCompilerOptions ,
340
+ compilerOptions ,
337
341
this . _angularCompilerHost ,
338
342
this . _program as ts . Program
339
343
) ;
@@ -345,7 +349,7 @@ export class AngularCompilerPlugin implements Tapable {
345
349
// Create the Angular program.
346
350
this . _program = createProgram ( {
347
351
rootNames : this . _tsFilenames ,
348
- options : this . _angularCompilerOptions ,
352
+ options : compilerOptions ,
349
353
host : this . _angularCompilerHost ,
350
354
oldProgram : this . _program as Program
351
355
} ) ;
@@ -543,7 +547,6 @@ export class AngularCompilerPlugin implements Tapable {
543
547
compiler . plugin ( 'done' , ( ) => {
544
548
this . _donePromise = null ;
545
549
this . _compilation = null ;
546
- this . _failedCompilation = false ;
547
550
} ) ;
548
551
549
552
// TODO: consider if it's better to remove this plugin and instead make it wait on the
@@ -618,7 +621,6 @@ export class AngularCompilerPlugin implements Tapable {
618
621
timeEnd ( 'AngularCompilerPlugin._make' ) ;
619
622
cb ( ) ;
620
623
} , ( err : any ) => {
621
- this . _failedCompilation = true ;
622
624
compilation . errors . push ( err . stack ) ;
623
625
timeEnd ( 'AngularCompilerPlugin._make' ) ;
624
626
cb ( ) ;
@@ -740,8 +742,6 @@ export class AngularCompilerPlugin implements Tapable {
740
742
// Reset changed files on successful compilation.
741
743
if ( emitResult && ! emitResult . emitSkipped && this . _compilation . errors . length === 0 ) {
742
744
this . _compilerHost . resetChangedFileTracker ( ) ;
743
- } else {
744
- this . _failedCompilation = true ;
745
745
}
746
746
}
747
747
timeEnd ( 'AngularCompilerPlugin._update' ) ;
@@ -803,7 +803,9 @@ export class AngularCompilerPlugin implements Tapable {
803
803
'AngularCompilerPlugin._emit.ts' ) ) ;
804
804
}
805
805
806
- if ( ! hasErrors ( allDiagnostics ) ) {
806
+ // Always emit on the first run, so that imports are processed by webpack and the user
807
+ // can trigger a rebuild by editing any file.
808
+ if ( ! hasErrors ( allDiagnostics ) || this . _firstRun ) {
807
809
sourceFiles . forEach ( ( sf ) => {
808
810
const timeLabel = `AngularCompilerPlugin._emit.ts+${ sf . fileName } +.emit` ;
809
811
time ( timeLabel ) ;
@@ -834,7 +836,9 @@ export class AngularCompilerPlugin implements Tapable {
834
836
'AngularCompilerPlugin._emit.ng' ) ) ;
835
837
}
836
838
837
- if ( ! hasErrors ( allDiagnostics ) ) {
839
+ // Always emit on the first run, so that imports are processed by webpack and the user
840
+ // can trigger a rebuild by editing any file.
841
+ if ( ! hasErrors ( allDiagnostics ) || this . _firstRun ) {
838
842
time ( 'AngularCompilerPlugin._emit.ng.emit' ) ;
839
843
const extractI18n = ! ! this . _angularCompilerOptions . i18nOutFile ;
840
844
const emitFlags = extractI18n ? EmitFlags . I18nBundle : EmitFlags . Default ;
0 commit comments