Skip to content

Commit

Permalink
feat(@ngtools/webpack): allow custom lazy module resource
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Nov 8, 2018
1 parent 13c057a commit aa0a676
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export interface AngularCompilerPluginOptions {

// added to the list of lazy routes
additionalLazyModules?: { [module: string]: string };
additionalLazyModuleResources?: string[];

// The ContextElementDependency of correct Webpack compilation.
// This is needed when there are multiple Webpack installs.
Expand Down Expand Up @@ -663,15 +664,19 @@ export class AngularCompilerPlugin {
// APFv6 does not have single FESM anymore. Instead of verifying if we're pointing to
// FESMs, we resolve the `@angular/core` path and verify that the path for the
// module starts with it.

// This may be slower but it will be compatible with both APF5, 6 and potential future
// versions (until the dynamic import appears outside of core I suppose).
// We resolve any symbolic links in order to get the real path that would be used in webpack.
const angularCoreDirname = fs.realpathSync(path.dirname(angularCorePackagePath));
const angularCoreResourceRoot = fs.realpathSync(path.dirname(angularCorePackagePath));

cmf.hooks.afterResolve.tapPromise('angular-compiler', async result => {
// Alter only request from Angular.
if (!result || !this.done || !result.resource.startsWith(angularCoreDirname)) {
// Alter only existing request from Angular or one of the additional lazy module resources.
const isLazyModuleResource = (resource: string) =>
resource.startsWith(angularCoreResourceRoot) ||
( this.options.additionalLazyModuleResources &&
this.options.additionalLazyModuleResources.includes(resource));

if (!result || !this.done || !isLazyModuleResource(result.resource)) {
return result;
}

Expand Down

0 comments on commit aa0a676

Please sign in to comment.