Skip to content

Commit 1226c36

Browse files
committed
fix(@ngtools/webpack): fix aot builds using npm packages that have lazy loaded modules
Currently, code splitting derived from routes with the loadChildren property only works if the resolved source file is a *.ts file in the source directory of your angular-cli project. If your project uses an npm package that has a route with loadChildren, the build will resolve the lazy loaded module as a *.d.ts definition file and then attempt to find an *.d.ts.ngfactory.ts file in the generated AOT directory, which does not exist. This fixes the path generation logic so the build will look for a *.ngfactory.ts file in $$_gendir/node_modules.
1 parent 446dc65 commit 1226c36

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ export class AotPlugin implements Tapable {
461461
if (this.skipCodeGeneration) {
462462
this._lazyRoutes[k] = lazyRoute;
463463
} else {
464-
const lr = path.relative(this.basePath, lazyRoute.replace(/\.ts$/, '.ngfactory.ts'));
465-
this._lazyRoutes[k + '.ngfactory'] = path.join(this.genDir, lr);
464+
const lr = path.relative(this.basePath, lazyRoute.replace(/(\.d)?\.ts$/, '.ngfactory.ts'));
465+
this._lazyRoutes[k + '.ngfactory'] = path.join(this.genDir, path.join('/', lr));
466466
}
467467
});
468468
})

0 commit comments

Comments
 (0)