@@ -7,6 +7,16 @@ import {LoaderContext, ModuleReason} from './webpack';
7
7
const loaderUtils = require ( 'loader-utils' ) ;
8
8
const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
9
9
10
+ // This is a map of changes which need to be made
11
+ const changeMap : { [ key : string ] : string } = {
12
+ platformBrowserDynamic : 'platformBrowser' ,
13
+ platformDynamicServer : 'platformServer'
14
+ } ;
15
+
16
+ const importLocations : { [ key : string ] : string } = {
17
+ platformBrowser : '@angular/platform-browser' ,
18
+ platformServer : '@angular/platform-server'
19
+ } ;
10
20
11
21
function _getContentOfKeyLiteral ( _source : ts . SourceFile , node : ts . Node ) : string {
12
22
if ( ! node ) {
@@ -205,9 +215,10 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
205
215
= refactor . findAstNodes ( access , ts . SyntaxKind . CallExpression , true ) as ts . CallExpression [ ] ;
206
216
return previous . concat ( expressions ) ;
207
217
} , [ ] )
218
+ . filter ( ( call : ts . CallExpression ) => call . expression . kind == ts . SyntaxKind . Identifier )
208
219
. filter ( ( call : ts . CallExpression ) => {
209
- return call . expression . kind == ts . SyntaxKind . Identifier
210
- && ( call . expression as ts . Identifier ) . text == 'platformBrowserDynamic' ;
220
+ // Find if the expression matches one of the replacement targets
221
+ return ! ! changeMap [ ( call . expression as ts . Identifier ) . text ] ;
211
222
} ) ;
212
223
213
224
if ( calls . length == 0 ) {
@@ -222,16 +233,25 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
222
233
refactor . replaceNode ( call . arguments [ 0 ] , entryModule . className + 'NgFactory' ) ;
223
234
} ) ;
224
235
225
- calls . forEach ( call => refactor . replaceNode ( call . expression , 'platformBrowser' ) ) ;
236
+ calls . forEach ( call => {
237
+ // Replace with mapped replacement
238
+ refactor . replaceNode ( call . expression , changeMap [ ( call . expression as ts . Identifier ) . text ] ) ;
239
+ } ) ;
226
240
227
241
bootstraps
228
242
. forEach ( ( bs : ts . PropertyAccessExpression ) => {
229
243
// This changes the call.
230
244
refactor . replaceNode ( bs . name , 'bootstrapModuleFactory' ) ;
231
245
} ) ;
232
246
233
- refactor . insertImport ( 'platformBrowser' , '@angular/platform-browser' ) ;
234
247
refactor . insertImport ( entryModule . className + 'NgFactory' , ngFactoryPath ) ;
248
+
249
+ // We need to import the additional imports which are used
250
+ Object . keys ( importLocations )
251
+ . filter ( imp => refactor . sourceMatch ( new RegExp ( imp ) ) )
252
+ . forEach ( imp => {
253
+ refactor . insertImport ( imp , importLocations [ imp ] ) ;
254
+ } ) ;
235
255
}
236
256
237
257
export function removeModuleIdOnlyForTesting ( refactor : TypeScriptFileRefactor ) {
0 commit comments