Skip to content

Commit 5150f82

Browse files
filipesilvavikerman
authored andcommitted
feat(@ngtools/webpack): allow custom lazy module resource (#12593)
1 parent 96606b3 commit 5150f82

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export interface AngularCompilerPluginOptions {
106106

107107
// added to the list of lazy routes
108108
additionalLazyModules?: { [module: string]: string };
109+
additionalLazyModuleResources?: string[];
109110

110111
// The ContextElementDependency of correct Webpack compilation.
111112
// This is needed when there are multiple Webpack installs.
@@ -663,15 +664,19 @@ export class AngularCompilerPlugin {
663664
// APFv6 does not have single FESM anymore. Instead of verifying if we're pointing to
664665
// FESMs, we resolve the `@angular/core` path and verify that the path for the
665666
// module starts with it.
666-
667667
// This may be slower but it will be compatible with both APF5, 6 and potential future
668668
// versions (until the dynamic import appears outside of core I suppose).
669669
// We resolve any symbolic links in order to get the real path that would be used in webpack.
670-
const angularCoreDirname = fs.realpathSync(path.dirname(angularCorePackagePath));
670+
const angularCoreResourceRoot = fs.realpathSync(path.dirname(angularCorePackagePath));
671671

672672
cmf.hooks.afterResolve.tapPromise('angular-compiler', async result => {
673-
// Alter only request from Angular.
674-
if (!result || !this.done || !result.resource.startsWith(angularCoreDirname)) {
673+
// Alter only existing request from Angular or one of the additional lazy module resources.
674+
const isLazyModuleResource = (resource: string) =>
675+
resource.startsWith(angularCoreResourceRoot) ||
676+
( this.options.additionalLazyModuleResources &&
677+
this.options.additionalLazyModuleResources.includes(resource));
678+
679+
if (!result || !this.done || !isLazyModuleResource(result.resource)) {
675680
return result;
676681
}
677682

0 commit comments

Comments
 (0)