@@ -3,6 +3,9 @@ import * as ts from 'typescript';
33import { AotPlugin } from './plugin' ;
44import { TypeScriptFileRefactor } from './refactor' ;
55
6+ const loaderUtils = require ( 'loader-utils' ) ;
7+
8+
69function _getContentOfKeyLiteral ( source : ts . SourceFile , node : ts . Node ) : string {
710 if ( node . kind == ts . SyntaxKind . Identifier ) {
811 return ( node as ts . Identifier ) . text ;
@@ -83,7 +86,7 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
8386 refactor . insertImport ( entryModule . className + 'NgFactory' , ngFactoryPath ) ;
8487}
8588
86- function _replaceResources ( refactor : TypeScriptFileRefactor ) {
89+ function _replaceResources ( refactor : TypeScriptFileRefactor ) : void {
8790 const sourceFile = refactor . sourceFile ;
8891
8992 // Find all object literals.
@@ -143,12 +146,11 @@ function _checkDiagnostics(refactor: TypeScriptFileRefactor) {
143146// Super simple TS transpiler loader for testing / isolated usage. does not type check!
144147export function ngcLoader ( source : string ) {
145148 this . cacheable ( ) ;
149+ const cb : any = this . async ( ) ;
146150
147151 const plugin = this . _compilation . _ngToolsWebpackPluginInstance as AotPlugin ;
148152 // We must verify that AotPlugin is an instance of the right class.
149153 if ( plugin && plugin instanceof AotPlugin ) {
150- const cb : any = this . async ( ) ;
151-
152154 const refactor = new TypeScriptFileRefactor (
153155 this . resourcePath , plugin . compilerHost , plugin . program ) ;
154156
@@ -180,11 +182,26 @@ export function ngcLoader(source: string) {
180182 } )
181183 . catch ( err => cb ( err ) ) ;
182184 } else {
183- return ts . transpileModule ( source , {
184- compilerOptions : {
185- target : ts . ScriptTarget . ES5 ,
186- module : ts . ModuleKind . ES2015 ,
185+ const options = loaderUtils . parseQuery ( this . query ) ;
186+ const tsConfigPath = options . tsConfigPath ;
187+ const tsConfig = ts . readConfigFile ( tsConfigPath , ts . sys . readFile ) ;
188+
189+ if ( tsConfig . error ) {
190+ throw tsConfig . error ;
191+ }
192+
193+ const compilerOptions = tsConfig . config . compilerOptions as ts . CompilerOptions ;
194+ for ( const key of Object . keys ( options ) ) {
195+ if ( key == 'tsConfigPath' ) {
196+ continue ;
187197 }
188- } ) . outputText ;
198+ compilerOptions [ key ] = options [ key ] ;
199+ }
200+ const compilerHost = ts . createCompilerHost ( compilerOptions ) ;
201+ const refactor = new TypeScriptFileRefactor ( this . resourcePath , compilerHost ) ;
202+ _replaceResources ( refactor ) ;
203+
204+ const result = refactor . transpile ( compilerOptions ) ;
205+ cb ( null , result . outputText , result . sourceMap ) ;
189206 }
190207}
0 commit comments