@@ -27,17 +27,18 @@ function _removeDecorators(fileName: string, source: string): string {
2727
2828
2929function _replaceBootstrap ( fileName : string , source : string , plugin : NgcWebpackPlugin ) {
30- const dirName = path . dirname ( fileName ) ;
31- const entryModuleName = plugin . entryModule . split ( '#' ) [ 0 ] + '.ngfactory' ;
32- const entryModule = path . join ( plugin . genDir , path . relative ( dirName , entryModuleName ) ) ;
33- const ngFactoryPath = './' + path . relative ( dirName , entryModule ) ;
30+ const basePath = plugin . angularCompilerOptions . basePath ;
31+ const entryModuleFileName = plugin . entryModule . split ( '#' ) [ 0 ] + '.ngfactory' ;
32+ const relativeEntryModulePath = path . relative ( basePath , entryModuleFileName ) ;
33+ const fullEntryModulePath = path . resolve ( plugin . genDir , relativeEntryModulePath ) ;
34+ const ngFactoryPath = './' + path . relative ( path . dirname ( fileName ) , fullEntryModulePath ) ;
3435
3536 return source
3637 . replace ( / ( i m p o r t .* ) \b p l a t f o r m B r o w s e r D y n a m i c \b ( .* \/ ) p l a t f o r m - b r o w s e r - d y n a m i c ( \b .* ) $ / m,
3738 '$1 platformBrowser $2platform-browser$3' )
3839 . replace ( / ^ ( [ \s \S ] * ) p l a t f o r m B r o w s e r D y n a m i c ( [ \s \S ] * ) .b o o t s t r a p M o d u l e ( [ \s \S ] * ) M o d u l e ( [ \s \S ] * ) $ / m,
3940 '$1platformBrowser$2.bootstrapModuleFactory$3ModuleNgFactory$4' )
40- . replace ( / ^ ( i m p o r t .* ) \b M o d u l e \b ( .* ) f r o m .* $ / m,
41+ . replace ( / ^ ( i m p o r t .* \w * ) M o d u l e \b ( .* ) f r o m .* $ / m,
4142 `$1ModuleNgFactory$2 from '${ ngFactoryPath } ';` ) ;
4243}
4344
@@ -48,27 +49,29 @@ export function ngcLoader(source: string) {
4849 if ( plugin && plugin instanceof NgcWebpackPlugin ) {
4950 const cb : any = this . async ( ) ;
5051
51- plugin . done . then ( ( ) => {
52- source = _removeDecorators ( this . resource , source ) ;
53- source = _replaceBootstrap ( this . resource , source , plugin ) ;
52+ plugin . done
53+ . then ( ( ) => {
54+ source = _removeDecorators ( this . resource , source ) ;
55+ source = _replaceBootstrap ( this . resource , source , plugin ) ;
5456
55- const result = ts . transpileModule ( source , {
56- compilerOptions : {
57- target : ts . ScriptTarget . ES5 ,
58- module : ts . ModuleKind . ES2015 ,
59- }
60- } ) ;
61-
62- if ( result . diagnostics && result . diagnostics . length ) {
63- let message = '' ;
64- result . diagnostics . forEach ( d => {
65- message += d . messageText + '\n' ;
57+ const result = ts . transpileModule ( source , {
58+ compilerOptions : {
59+ target : ts . ScriptTarget . ES5 ,
60+ module : ts . ModuleKind . ES2015 ,
61+ }
6662 } ) ;
67- cb ( new Error ( message ) ) ;
68- }
6963
70- cb ( null , result . outputText , result . sourceMapText ? JSON . parse ( result . sourceMapText ) : null ) ;
71- } ) ;
64+ if ( result . diagnostics && result . diagnostics . length ) {
65+ let message = '' ;
66+ result . diagnostics . forEach ( d => {
67+ message += d . messageText + '\n' ;
68+ } ) ;
69+ cb ( new Error ( message ) ) ;
70+ }
71+
72+ cb ( null , result . outputText , result . sourceMapText ? JSON . parse ( result . sourceMapText ) : null ) ;
73+ } )
74+ . catch ( err => cb ( err ) ) ;
7275 } else {
7376 return ts . transpileModule ( source , {
7477 compilerOptions : {
0 commit comments