From 18ee60baa1aa9519245ecd9bf2d8b2c1f3503ce9 Mon Sep 17 00:00:00 2001 From: Andrew Steel Date: Thu, 23 Mar 2017 11:30:35 -0400 Subject: [PATCH] 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. --- packages/@ngtools/webpack/src/plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index 60da107cb497..9f7e3d7604f1 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -461,7 +461,8 @@ export class AotPlugin implements Tapable { if (this.skipCodeGeneration) { this._lazyRoutes[k] = lazyRoute; } else { - const lr = path.relative(this.basePath, lazyRoute.replace(/\.ts$/, '.ngfactory.ts')); + const factoryPath = lazyRoute.replace(/(\.d)?\.ts$/, '.ngfactory.ts'); + const lr = path.join(path.sep, path.relative(this.basePath, factoryPath)); this._lazyRoutes[k + '.ngfactory'] = path.join(this.genDir, lr); } });