@@ -11,6 +11,8 @@ import {
1111import { workaroundResolve } from '@ngtools/webpack/src/compiler_host' ;
1212import { AngularCompilerPlugin } from '@ngtools/webpack' ;
1313
14+ import { getFirstNode } from './ast-utils' ;
15+
1416export function nsReplaceBootstrap ( getNgCompiler : ( ) => AngularCompilerPlugin ) : ts . TransformerFactory < ts . SourceFile > {
1517 const shouldTransform = ( fileName ) => ! fileName . endsWith ( '.ngfactory.ts' ) && ! fileName . endsWith ( '.ngstyle.ts' ) ;
1618 const getTypeChecker = ( ) => getNgCompiler ( ) . typeChecker ;
@@ -77,23 +79,37 @@ export function nsReplaceBootstrap(getNgCompiler: () => AngularCompilerPlugin):
7779 const idPlatformBrowser = ts . createUniqueName ( '__NgCli_bootstrap_' ) ;
7880 const idNgFactory = ts . createUniqueName ( '__NgCli_bootstrap_' ) ;
7981
82+ const firstNode = getFirstNode ( sourceFile ) ;
83+
8084 // Add the transform operations.
8185 const factoryClassName = entryModule . className + 'NgFactory' ;
8286 const factoryModulePath = normalizedEntryModulePath + '.ngfactory' ;
8387 ops . push (
84- // Insert an import of the module factory:
88+ // Insert an import of the {N} Angular static bootstrap module in the beginning of the file:
89+ // import * as __NgCli_bootstrap_2 from "nativescript-angular/platform-static";
90+ ...insertStarImport (
91+ sourceFile ,
92+ idPlatformBrowser ,
93+ 'nativescript-angular/platform-static' ,
94+ firstNode ,
95+ true ,
96+ ) ,
97+
98+ // Insert an import of the module factory in the beginning of the file:
8599 // import * as __NgCli_bootstrap_1 from "./app.module.ngfactory";
86- ...insertStarImport ( sourceFile , idNgFactory , factoryModulePath ) ,
100+ ...insertStarImport (
101+ sourceFile ,
102+ idNgFactory ,
103+ factoryModulePath ,
104+ firstNode ,
105+ true ,
106+ ) ,
87107
88108 // Replace the NgModule nodes with NgModuleFactory nodes
89109 // from 'AppModule' to 'AppModuleNgFactory'
90110 new ReplaceNodeOperation ( sourceFile , entryModuleIdentifier ,
91111 ts . createPropertyAccess ( idNgFactory , ts . createIdentifier ( factoryClassName ) ) ) ,
92112
93- // Insert an import of the {N} Angular static bootstrap module:
94- // import * as __NgCli_bootstrap_2 from "nativescript-angular/platform-static";
95- ...insertStarImport ( sourceFile , idPlatformBrowser , 'nativescript-angular/platform-static' ) ,
96-
97113 // Replace 'platformNativeScriptDynamic' with 'platformNativeScript'
98114 // and elide all imports of 'platformNativeScriptDynamic'
99115 new ReplaceNodeOperation ( sourceFile , platformBrowserDynamicIdentifier ,
0 commit comments