@@ -3,6 +3,9 @@ import * as ts from 'typescript';
3
3
import { AotPlugin } from './plugin' ;
4
4
import { TypeScriptFileRefactor } from './refactor' ;
5
5
6
+ const loaderUtils = require ( 'loader-utils' ) ;
7
+
8
+
6
9
function _getContentOfKeyLiteral ( source : ts . SourceFile , node : ts . Node ) : string {
7
10
if ( node . kind == ts . SyntaxKind . Identifier ) {
8
11
return ( node as ts . Identifier ) . text ;
@@ -83,7 +86,7 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
83
86
refactor . insertImport ( entryModule . className + 'NgFactory' , ngFactoryPath ) ;
84
87
}
85
88
86
- function _replaceResources ( refactor : TypeScriptFileRefactor ) {
89
+ function _replaceResources ( refactor : TypeScriptFileRefactor ) : void {
87
90
const sourceFile = refactor . sourceFile ;
88
91
89
92
// Find all object literals.
@@ -143,12 +146,11 @@ function _checkDiagnostics(refactor: TypeScriptFileRefactor) {
143
146
// Super simple TS transpiler loader for testing / isolated usage. does not type check!
144
147
export function ngcLoader ( source : string ) {
145
148
this . cacheable ( ) ;
149
+ const cb : any = this . async ( ) ;
146
150
147
151
const plugin = this . _compilation . _ngToolsWebpackPluginInstance as AotPlugin ;
148
152
// We must verify that AotPlugin is an instance of the right class.
149
153
if ( plugin && plugin instanceof AotPlugin ) {
150
- const cb : any = this . async ( ) ;
151
-
152
154
const refactor = new TypeScriptFileRefactor (
153
155
this . resourcePath , plugin . compilerHost , plugin . program ) ;
154
156
@@ -180,11 +182,26 @@ export function ngcLoader(source: string) {
180
182
} )
181
183
. catch ( err => cb ( err ) ) ;
182
184
} 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 ;
187
197
}
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 ) ;
189
206
}
190
207
}
0 commit comments