@@ -424,6 +424,28 @@ function _getResourcesUrls(refactor: TypeScriptFileRefactor): string[] {
424424}
425425
426426
427+ function _getImports ( refactor : TypeScriptFileRefactor ,
428+ compilerOptions : ts . CompilerOptions ,
429+ host : ts . ModuleResolutionHost ,
430+ cache : ts . ModuleResolutionCache ) : string [ ] {
431+ const containingFile = refactor . fileName ;
432+
433+ return refactor . findAstNodes ( null , ts . SyntaxKind . ImportDeclaration , false )
434+ . map ( ( clause : ts . ImportDeclaration ) => {
435+ const moduleName = ( clause . moduleSpecifier as ts . StringLiteral ) . text ;
436+ const resolved = ts . resolveModuleName (
437+ moduleName , containingFile , compilerOptions , host , cache ) ;
438+
439+ if ( resolved . resolvedModule ) {
440+ return resolved . resolvedModule . resolvedFileName ;
441+ } else {
442+ return null ;
443+ }
444+ } )
445+ . filter ( x => x ) ;
446+ }
447+
448+
427449/**
428450 * Recursively calls diagnose on the plugins for all the reverse dependencies.
429451 * @private
@@ -539,6 +561,13 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
539561 const refactor = new TypeScriptFileRefactor (
540562 sourceFileName , plugin . compilerHost , plugin . program , source ) ;
541563
564+ // Force a few compiler options to make sure we get the result we want.
565+ const compilerOptions : ts . CompilerOptions = Object . assign ( { } , plugin . compilerOptions , {
566+ inlineSources : true ,
567+ inlineSourceMap : false ,
568+ sourceRoot : plugin . basePath
569+ } ) ;
570+
542571 Promise . resolve ( )
543572 . then ( ( ) => {
544573 if ( ! plugin . skipCodeGeneration ) {
@@ -570,6 +599,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
570599 _getResourcesUrls ( refactor ) . forEach ( ( url : string ) => {
571600 this . addDependency ( path . resolve ( path . dirname ( sourceFileName ) , url ) ) ;
572601 } ) ;
602+ _getImports ( refactor , compilerOptions , plugin . compilerHost , plugin . moduleResolutionCache )
603+ . forEach ( ( importString : string ) => this . addDependency ( importString ) ) ;
573604 } )
574605 . then ( ( ) => {
575606 if ( source ) {
@@ -594,13 +625,6 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
594625 }
595626 }
596627
597- // Force a few compiler options to make sure we get the result we want.
598- const compilerOptions : ts . CompilerOptions = Object . assign ( { } , plugin . compilerOptions , {
599- inlineSources : true ,
600- inlineSourceMap : false ,
601- sourceRoot : plugin . basePath
602- } ) ;
603-
604628 const result = refactor . transpile ( compilerOptions ) ;
605629
606630 if ( plugin . failedCompilation ) {
0 commit comments