Skip to content

Commit 14f32b2

Browse files
committed
fix(aot): add baseurl and fix module resolution.
loadChildren resolution now uses the same resolution as imports (using the TypeScript language service).
1 parent 88131a0 commit 14f32b2

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/webpack/src/plugin.ts

+7-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export interface AotPluginOptions {
2828

2929
export interface LazyRoute {
3030
moduleRoute: ModuleRoute;
31-
moduleRelativePath: string;
3231
moduleAbsolutePath: string;
3332
}
3433

@@ -260,10 +259,8 @@ export class AotPlugin {
260259
}
261260

262261
private _resolveModulePath(module: ModuleRoute, containingFile: string) {
263-
if (module.path.startsWith('.')) {
264-
return path.join(path.dirname(containingFile), module.path);
265-
}
266-
return module.path;
262+
return this._reflectorHost.findDeclaration(module.path, module.className, containingFile)
263+
.filePath;
267264
}
268265

269266
private _processNgModule(module: ModuleRoute, containingFile: string | null): LazyRouteMap {
@@ -278,14 +275,9 @@ export class AotPlugin {
278275
const entryNgModuleMetadata = this.getNgModuleMetadata(staticSymbol);
279276
const loadChildrenRoute: LazyRoute[] = this.extractLoadChildren(entryNgModuleMetadata)
280277
.map(route => {
281-
const mr = ModuleRoute.fromString(route);
282-
const relativePath = this._resolveModulePath(mr, relativeModulePath);
283-
const absolutePath = path.join(this.genDir, relativePath);
284-
return {
285-
moduleRoute: mr,
286-
moduleRelativePath: relativePath,
287-
moduleAbsolutePath: absolutePath
288-
};
278+
const moduleRoute = ModuleRoute.fromString(route);
279+
const moduleAbsolutePath = this._resolveModulePath(moduleRoute, relativeModulePath);
280+
return { moduleRoute, moduleAbsolutePath };
289281
});
290282
const resultMap: LazyRouteMap = loadChildrenRoute
291283
.reduce((acc: LazyRouteMap, curr: LazyRoute) => {
@@ -347,7 +339,8 @@ export class AotPlugin {
347339
}
348340
})
349341
// Poor man's flat map.
350-
.reduce((acc: any[], i: any) => acc.concat(i), []))
342+
.reduce((acc: any[], i: any) => acc.concat(i), [])
343+
)
351344
.filter(x => !!x);
352345
}
353346

0 commit comments

Comments
 (0)