@@ -27,17 +27,18 @@ function _removeDecorators(fileName: string, source: string): string {
27
27
28
28
29
29
function _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 ) ;
34
35
35
36
return source
36
37
. 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,
37
38
'$1 platformBrowser $2platform-browser$3' )
38
39
. 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,
39
40
'$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,
41
42
`$1ModuleNgFactory$2 from '${ ngFactoryPath } ';` ) ;
42
43
}
43
44
@@ -48,27 +49,29 @@ export function ngcLoader(source: string) {
48
49
if ( plugin && plugin instanceof NgcWebpackPlugin ) {
49
50
const cb : any = this . async ( ) ;
50
51
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 ) ;
54
56
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
+ }
66
62
} ) ;
67
- cb ( new Error ( message ) ) ;
68
- }
69
63
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 ) ) ;
72
75
} else {
73
76
return ts . transpileModule ( source , {
74
77
compilerOptions : {
0 commit comments