@@ -581,18 +581,35 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
581581 result . sourceMap = JSON . stringify ( sourceMap ) ;
582582 }
583583
584- // Dependencies must use system path separator.
585- // TODO: move the denormalizer into it's own helper.
586- result . errorDependencies . forEach ( dep => this . addDependency ( dep . replace ( / \/ / g, path . sep ) ) ) ;
587- const dependencies = plugin . getDependencies ( sourceFileName ) ;
588- dependencies . forEach ( dep => this . addDependency ( dep . replace ( / \/ / g, path . sep ) ) ) ;
589-
590- // Also add the original file dependencies to virtual files.
591- const virtualFilesRe = / \. (?: n g f a c t o r y | c s s \. s h i m \. n g s t y l e ) \. j s $ / ;
592- if ( virtualFilesRe . test ( sourceFileName ) ) {
593- const originalFile = sourceFileName . replace ( virtualFilesRe , '.ts' ) ;
584+ // Manually add the dependencies for TS files.
585+ // Type only imports will be stripped out by compilation so we need to add them as
586+ // as dependencies.
587+ // Component resources files (html and css templates) also need to be added manually for
588+ // AOT, so that this file is reloaded when they change.
589+ if ( sourceFileName . endsWith ( '.ts' ) ) {
590+ result . errorDependencies . forEach ( dep => this . addDependency ( dep ) ) ;
591+ const dependencies = plugin . getDependencies ( sourceFileName ) ;
592+ dependencies . forEach ( dep => this . addDependency ( dep ) ) ;
593+ }
594+
595+ // NgFactory files depend on the component template, but we can't know what that file
596+ // is (if any). So we add all the dependencies that the original component file has
597+ // to the factory as well, which includes html and css templates.
598+ const ngFactoryRe = / \. n g f a c t o r y .j s $ / ;
599+ if ( ngFactoryRe . test ( sourceFileName ) ) {
600+ const originalFile = sourceFileName . replace ( ngFactoryRe , '.ts' ) ;
594601 const origDependencies = plugin . getDependencies ( originalFile ) ;
595- origDependencies . forEach ( dep => this . addDependency ( dep . replace ( / \/ / g, path . sep ) ) ) ;
602+ origDependencies . forEach ( dep => this . addDependency ( dep ) ) ;
603+ }
604+
605+ // NgStyle files depend on the style file they represent.
606+ // E.g. `some-style.less.shim.ngstyle.js` depends on `some-style.less`.
607+ // Those files can in turn depend on others, so we have to add them all.
608+ const ngStyleRe = / \. s h i m \. n g s t y l e \. j s $ / ;
609+ if ( ngStyleRe . test ( sourceFileName ) ) {
610+ const styleFile = sourceFileName . replace ( ngStyleRe , '' ) ;
611+ const styleDependencies = plugin . getResourceDependencies ( styleFile ) ;
612+ styleDependencies . forEach ( dep => this . addDependency ( dep ) ) ;
596613 }
597614
598615 timeEnd ( timeLabel ) ;
0 commit comments