Skip to content

Commit dd518df

Browse files
Broccohansl
authored andcommitted
fix(@ngtools/webpack): Change to modify module map to for universal
Remove the manipulation of path and name to string out ngfactory references
1 parent dc218c0 commit dd518df

File tree

3 files changed

+18
-150
lines changed

3 files changed

+18
-150
lines changed

packages/@ngtools/webpack/src/transformers/export_lazy_module_map.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ describe('export_lazy_module_map', () => {
3434
export { AppModule } from './app/app.module';
3535
`;
3636
// tslint:disable:max-line-length
37-
const output = stripIndent`
38-
import * as __lazy_0__ from "app/lazy/lazy.module.ts";
39-
import * as __lazy_1__ from "app/lazy2/lazy2.module.ts";
37+
const expected = stripIndent`
38+
import * as __lazy_0__ from "app/lazy/lazy.module.ngfactory.ts";
39+
import * as __lazy_1__ from "app/lazy2/lazy2.module.ngfactory.ts";
4040
export { AppModule } from './app/app.module';
41-
export var LAZY_MODULE_MAP = { "./lazy/lazy.module#LazyModule": __lazy_0__.LazyModule, "./lazy2/lazy2.module#LazyModule2": __lazy_1__.LazyModule2 };
41+
export var LAZY_MODULE_MAP = { "./lazy/lazy.module#LazyModule": __lazy_0__.LazyModuleNgFactory, "./lazy2/lazy2.module#LazyModule2": __lazy_1__.LazyModule2NgFactory };
4242
`;
4343
// tslint:enable:max-line-length
4444

@@ -50,6 +50,6 @@ describe('export_lazy_module_map', () => {
5050
});
5151
const result = transformTypescript(input, transformOpsCb);
5252

53-
expect(oneLine`${result}`).toEqual(oneLine`${output}`);
53+
expect(oneLine`${result}`).toEqual(oneLine`${expected}`);
5454
});
5555
});

packages/@ngtools/webpack/src/transformers/export_lazy_module_map.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,8 @@ export function exportLazyModuleMap(
1818

1919
const modules = Object.keys(lazyRoutes)
2020
.map((loadChildrenString) => {
21-
let [, moduleName] = loadChildrenString.split('#');
22-
let modulePath = lazyRoutes[loadChildrenString];
23-
24-
if (modulePath.match(/\.ngfactory\.[jt]s$/)) {
25-
modulePath = modulePath.replace('.ngfactory', '');
26-
moduleName = moduleName.replace('NgFactory', '');
27-
loadChildrenString = loadChildrenString
28-
.replace('.ngfactory', '')
29-
.replace('NgFactory', '');
30-
}
21+
const [, moduleName] = loadChildrenString.split('#');
22+
const modulePath = lazyRoutes[loadChildrenString];
3123

3224
return {
3325
modulePath,
@@ -52,10 +44,17 @@ export function exportLazyModuleMap(
5244
});
5345

5446
const lazyModuleObjectLiteral = ts.createObjectLiteral(
55-
modules.map((mod, idx) => ts.createPropertyAssignment(
56-
ts.createLiteral(mod.loadChildrenString),
57-
ts.createPropertyAccess(ts.createIdentifier(`__lazy_${idx}__`), mod.moduleName))
58-
)
47+
modules.map((mod, idx) => {
48+
let [modulePath, moduleName] = mod.loadChildrenString.split('#');
49+
if (modulePath.match(/\.ngfactory/)) {
50+
modulePath = modulePath.replace('.ngfactory', '');
51+
moduleName = moduleName.replace('NgFactory', '');
52+
}
53+
54+
return ts.createPropertyAssignment(
55+
ts.createLiteral(`${modulePath}#${moduleName}`),
56+
ts.createPropertyAccess(ts.createIdentifier(`__lazy_${idx}__`), mod.moduleName));
57+
})
5958
);
6059

6160
const lazyModuleVariableStmt = ts.createVariableStatement(

tests/e2e/tests/build/platform-server-lazy-module-map.ts

-131
This file was deleted.

0 commit comments

Comments
 (0)