Skip to content

Commit 9bd6d43

Browse files
FrozenPandazBrocco
authored andcommitted
feat(@ngtools/webpack): add support for render module api
1 parent 27902c0 commit 9bd6d43

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

packages/@ngtools/webpack/src/loader.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,32 @@ function _replacePlatform(
222222
}
223223

224224

225-
function _replaceBootstrap(refactor: TypeScriptFileRefactor, call: ts.CallExpression) {
226-
// If bootstrapModule can't be found, bail out early.
227-
if (!call.getText().includes('bootstrapModule')) {
228-
return;
229-
}
225+
function _replaceBootstrapOrRender(refactor: TypeScriptFileRefactor, call: ts.CallExpression) {
226+
// If neither bootstrapModule or renderModule can't be found, bail out early.
227+
let replacementTarget: string;
228+
let identifier: ts.Identifier;
229+
if (call.getText().includes('bootstrapModule')) {
230+
if (call.expression.kind != ts.SyntaxKind.PropertyAccessExpression) {
231+
return;
232+
}
230233

231-
if (call.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
234+
replacementTarget = 'bootstrapModule';
232235
const access = call.expression as ts.PropertyAccessExpression;
236+
identifier = access.name;
237+
_replacePlatform(refactor, access);
233238

234-
if (access.name.text === 'bootstrapModule') {
235-
_replacePlatform(refactor, access);
236-
refactor.replaceNode(access.name, 'bootstrapModuleFactory');
239+
} else if (call.getText().includes('renderModule')) {
240+
if (call.expression.kind != ts.SyntaxKind.Identifier) {
241+
return;
237242
}
243+
244+
replacementTarget = 'renderModule';
245+
identifier = call.expression as ts.Identifier;
246+
refactor.insertImport('renderModuleFactory', '@angular/platform-server');
247+
}
248+
249+
if (identifier && identifier.text === replacementTarget) {
250+
refactor.replaceNode(identifier, replacementTarget + 'Factory');
238251
}
239252
}
240253

@@ -268,7 +281,8 @@ function _replaceEntryModule(plugin: AotPlugin, refactor: TypeScriptFileRefactor
268281
modules
269282
.forEach(reference => {
270283
refactor.replaceNode(reference, factoryClassName);
271-
_replaceBootstrap(refactor, _getCaller(reference));
284+
const caller = _getCaller(reference);
285+
_replaceBootstrapOrRender(refactor, caller);
272286
});
273287
}
274288

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import 'core-js/es7/reflect';
2-
import {platformDynamicServer} from '@angular/platform-server';
2+
import {platformDynamicServer, renderModule} from '@angular/platform-server';
33
import {AppModule} from './app.module';
44

55
AppModule.testProp = 'testing';
66

77
platformDynamicServer().bootstrapModule(AppModule);
8+
renderModule(AppModule, {
9+
document: '<app-root></app-root>',
10+
url: '/'
11+
});

tests/e2e/tests/packages/webpack/server.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default function(skipCleaning: () => void) {
1717
.then(() => expectFileToMatch('dist/app.main.js',
1818
new RegExp('AppComponent.ctorParameters = .*MyInjectable'))
1919
.then(() => expectFileToMatch('dist/app.main.js',
20-
/AppModule.*\.testProp = \'testing\'/)
20+
/AppModule \*\/\].*\.testProp = \'testing\'/))
21+
.then(() => expectFileToMatch('dist/app.main.js',
22+
/renderModuleFactory \*\/\].*\/\* AppModuleNgFactory \*\/\]/))
2123
.then(() => skipCleaning());
2224
}

0 commit comments

Comments
 (0)