Skip to content

Shared module code imported in lazy loaded modules is duplicated #2771

@mbellezi

Description

@mbellezi

OS?

MacOS

Versions.

angular-cli: 1.0.0-beta.17
node: 6.6.0
os: darwin x64

I'm trying to organize my web app in lazy loaded modules for better loading performance, but I'm running into this problem:

Suppose my app structure is like this:

---app.component.ts
---app.module.ts
---app.routes.ts
---shared/
--------mainshared,module.ts
---join/ (lazy)
---site/ (lazy)
-------site.component.ts
-------site.module.ts
-------site.routes.ts
-------shared/
-------shared/siteshared.module.ts
-------profile (lazy)
-------------profile.component.ts
-------------profile.module.ts
-------------profile.routes.ts
-------home (lazy)
-------------home.component.ts
-------------home.module.ts
-------------home.routes.ts

When the app loads, it bootstraps the app.module. The app.module imports the mainshared.module that has all the basic shared code necessary to start the app like Angular Material, Common module etc.
The app.module redirects then to join, site/profile or site/home depending on localStorage data.

The site.module imports siteshared.module (that imports mainshared.module).
Both profile.module and home.module imports siteshared.module.

After building, I have a main bundle and a separate bundle for: join, site, site/profile and site/home. This is correct. The problem is that the code (components, directives, etc) declared in the siteshared module are been repeated in the siteshared, profile and home bundles. It should stay only in the site bundle and been only referenced on the profile and home bundles.

The shared code from the mainshared.module (at the app level) is correctly not duplicated below.
This odd behavior is preventing sharing code at the second hierarchical level.

Is this a bug or something by angular-cli/webpack design?

Thank you!

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions