@@ -101,7 +101,6 @@ export class AngularCompilerPlugin implements Tapable {
101101 private _donePromise : Promise < void > | null ;
102102 private _compiler : any = null ;
103103 private _compilation : any = null ;
104- private _failedCompilation = false ;
105104
106105 // TypeChecker process.
107106 private _forkTypeChecker = true ;
@@ -115,7 +114,6 @@ export class AngularCompilerPlugin implements Tapable {
115114
116115 get options ( ) { return this . _options ; }
117116 get done ( ) { return this . _donePromise ; }
118- get failedCompilation ( ) { return this . _failedCompilation ; }
119117 get entryModule ( ) {
120118 const splitted = this . _entryModule . split ( '#' ) ;
121119 const path = splitted [ 0 ] ;
@@ -327,13 +325,19 @@ export class AngularCompilerPlugin implements Tapable {
327325 this . _updateForkedTypeChecker ( changedTsFiles ) ;
328326 }
329327
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+ } ;
331334
335+ if ( this . _JitMode ) {
332336 // Create the TypeScript program.
333337 time ( 'AngularCompilerPlugin._createOrUpdateProgram.ts.createProgram' ) ;
334338 this . _program = ts . createProgram (
335339 this . _tsFilenames ,
336- this . _angularCompilerOptions ,
340+ compilerOptions ,
337341 this . _angularCompilerHost ,
338342 this . _program as ts . Program
339343 ) ;
@@ -345,7 +349,7 @@ export class AngularCompilerPlugin implements Tapable {
345349 // Create the Angular program.
346350 this . _program = createProgram ( {
347351 rootNames : this . _tsFilenames ,
348- options : this . _angularCompilerOptions ,
352+ options : compilerOptions ,
349353 host : this . _angularCompilerHost ,
350354 oldProgram : this . _program as Program
351355 } ) ;
@@ -543,7 +547,6 @@ export class AngularCompilerPlugin implements Tapable {
543547 compiler . plugin ( 'done' , ( ) => {
544548 this . _donePromise = null ;
545549 this . _compilation = null ;
546- this . _failedCompilation = false ;
547550 } ) ;
548551
549552 // 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 {
618621 timeEnd ( 'AngularCompilerPlugin._make' ) ;
619622 cb ( ) ;
620623 } , ( err : any ) => {
621- this . _failedCompilation = true ;
622624 compilation . errors . push ( err . stack ) ;
623625 timeEnd ( 'AngularCompilerPlugin._make' ) ;
624626 cb ( ) ;
@@ -740,8 +742,6 @@ export class AngularCompilerPlugin implements Tapable {
740742 // Reset changed files on successful compilation.
741743 if ( emitResult && ! emitResult . emitSkipped && this . _compilation . errors . length === 0 ) {
742744 this . _compilerHost . resetChangedFileTracker ( ) ;
743- } else {
744- this . _failedCompilation = true ;
745745 }
746746 }
747747 timeEnd ( 'AngularCompilerPlugin._update' ) ;
@@ -803,7 +803,9 @@ export class AngularCompilerPlugin implements Tapable {
803803 'AngularCompilerPlugin._emit.ts' ) ) ;
804804 }
805805
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 ) {
807809 sourceFiles . forEach ( ( sf ) => {
808810 const timeLabel = `AngularCompilerPlugin._emit.ts+${ sf . fileName } +.emit` ;
809811 time ( timeLabel ) ;
@@ -834,7 +836,9 @@ export class AngularCompilerPlugin implements Tapable {
834836 'AngularCompilerPlugin._emit.ng' ) ) ;
835837 }
836838
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 ) {
838842 time ( 'AngularCompilerPlugin._emit.ng.emit' ) ;
839843 const extractI18n = ! ! this . _angularCompilerOptions . i18nOutFile ;
840844 const emitFlags = extractI18n ? EmitFlags . I18nBundle : EmitFlags . Default ;
0 commit comments