Skip to content

Commit

Permalink
fix(@ngtools/webpack): fix Angular 5 lazy routes in es2015
Browse files Browse the repository at this point in the history
Fix #7689
  • Loading branch information
filipesilva authored and Brocco committed Sep 22, 2017
1 parent 4f0f652 commit 2da72e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,22 @@ export class AngularCompilerPlugin implements Tapable {
// being built.
const angularCoreModuleDir = path.dirname(angularCoreModulePath).split(/node_modules/).pop();

// Also support the es2015 in Angular versions that have it.
let angularCoreEs2015Dir: string | undefined;
if (angularCorePackageJson['es2015']) {
const angularCoreEs2015Path = path.resolve(path.dirname(angularCorePackagePath),
angularCorePackageJson['es2015']);
angularCoreEs2015Dir = path.dirname(angularCoreEs2015Path).split(/node_modules/).pop();
}

cmf.plugin('after-resolve', (result: any, callback: (err?: any, request?: any) => void) => {
if (!result) {
return callback();
}

// Alter only request from Angular.
if (angularCoreModuleDir && !result.resource.endsWith(angularCoreModuleDir)) {
if (!(angularCoreModuleDir && result.resource.endsWith(angularCoreModuleDir))
&& !(angularCoreEs2015Dir && result.resource.endsWith(angularCoreEs2015Dir))) {
return callback(null, result);
}

Expand Down
11 changes: 10 additions & 1 deletion packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ export class AotPlugin implements Tapable {
// being built.
const angularCoreModuleDir = path.dirname(angularCoreModulePath).split(/node_modules/).pop();

// Also support the es2015 in Angular versions that have it.
let angularCoreEs2015Dir: string | undefined;
if (angularCorePackageJson['es2015']) {
const angularCoreEs2015Path = path.resolve(path.dirname(angularCorePackagePath),
angularCorePackageJson['es2015']);
angularCoreEs2015Dir = path.dirname(angularCoreEs2015Path).split(/node_modules/).pop();
}

cmf.plugin('after-resolve', (result: any, callback: (err?: any, request?: any) => void) => {
if (!result) {
return callback();
Expand All @@ -368,7 +376,8 @@ export class AotPlugin implements Tapable {
// The other logic is for flat modules and requires reading the package.json of angular
// (see above).
if (!result.resource.endsWith(path.join('@angular/core/src/linker'))
&& (angularCoreModuleDir && !result.resource.endsWith(angularCoreModuleDir))) {
&& !(angularCoreModuleDir && result.resource.endsWith(angularCoreModuleDir))
&& !(angularCoreEs2015Dir && result.resource.endsWith(angularCoreEs2015Dir))) {
return callback(null, result);
}

Expand Down

0 comments on commit 2da72e5

Please sign in to comment.