Skip to content

Commit f82202b

Browse files
committed
bug(build): Remove moduleId from components when building
Fixes angular#3576
1 parent db4e024 commit f82202b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

+26-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
8787
refactor.insertImport(entryModule.className + 'NgFactory', ngFactoryPath);
8888
}
8989

90+
function _removeModuleId(refactor: TypeScriptFileRefactor) {
91+
const sourceFile = refactor.sourceFile;
92+
93+
// Find all object literals.
94+
refactor.findAstNodes(sourceFile, ts.SyntaxKind.ObjectLiteralExpression, true)
95+
// Get all their property assignments.
96+
.map(node => refactor.findAstNodes(node, ts.SyntaxKind.PropertyAssignment))
97+
// Flatten into a single array (from an array of array<property assignments>).
98+
.reduce((prev, curr) => curr ? prev.concat(curr) : prev, [])
99+
// Remove every property assignment that aren't 'loadChildren'.
100+
.filter((node: ts.PropertyAssignment) => {
101+
const key = _getContentOfKeyLiteral(sourceFile, node.name);
102+
if (!key) {
103+
// key is an expression, can't do anything.
104+
return false;
105+
}
106+
return key == 'moduleId';
107+
})
108+
.forEach((node: ts.PropertyAssignment) => {
109+
refactor.removeNode(node);
110+
});
111+
}
112+
90113
function _replaceResources(refactor: TypeScriptFileRefactor): void {
91114
const sourceFile = refactor.sourceFile;
92115

@@ -163,7 +186,9 @@ export function ngcLoader(source: string) {
163186
.then(() => _removeDecorators(refactor))
164187
.then(() => _replaceBootstrap(plugin, refactor));
165188
} else {
166-
return _replaceResources(refactor);
189+
return Promise.resolve()
190+
.then(() => _replaceResources(refactor))
191+
.then(() => _removeModuleId(refactor));
167192
}
168193
})
169194
.then(() => {

0 commit comments

Comments
 (0)