question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicated Material modules in aot generaed lazy load chunk files (Angular CLI)

See original GitHub issue

Bug, feature request, or proposal:

I’ve taken a look at my (lazy load) chunk files generated by Angular CLI (--prod so with aot) and I wonder why do I have the used material components also in there floating around when they are already in the vendor.bundle file? Is this an issue on Material side, Angular CLI or it’s just the way it has to be?


Lazy load chunk 1

mat-chunk1

Lazy load chunk 2

mat-chunk2

Vendor bundle

mat-vendor

What is the expected behavior?

Don’t duplicate the Material modules throuh the app - at least not the styles.

What is the current behavior?

Every chunk gets the modules (& css) for the md components that it components use added

What are the steps to reproduce?

Plunker won’t do it so i’ve added a repo. https://github.com/bboehm86/mat-chunk-test

  • You’ll need @angular/cli@1.0.0-beta.32.3
  • source-map-explorer might be helful (run npm run build to generate files with sourcemaps)

What is the use-case or motivation for changing an existing behavior?

smaller chunk sizes

Which versions of Angular, Material, OS, browsers are affected?

Angular 2.x, Angular CLI 1.0.0-beta.32.3, all Material versions

Is there anything else we should know?

That is probably not related and a webpack issue… but in the vendor.bundle everything for Material gets inclued no matter what. The only way to prevent that is to include just the modules we use. On both, our app.module and then in every module that uses a component

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:15

github_iconTop GitHub Comments

2reactions
kblestargecommented, Jun 15, 2017

@bboehm86 this is what my custom-ng-materials.module.ts file looks like:

import {MdButtonModule, MdCheckboxModule, MdInputModule, MdSelectModule, MdCardModule} from '@angular/material';
import {NgModule} from "@angular/core";

@NgModule({
    exports: [
        MdButtonModule,
        MdCheckboxModule,
        MdInputModule,
        MdSelectModule,
        MdCardModule,
    ],
})
export class CustomNgMaterialsModule { }

This module is then imported into each module that has declared components using any of these material components. I think I’m doing everything correctly according to the Getting Started Guide and your demo app. What do you think is the problem?

2reactions
bboehm86commented, May 25, 2017

I’m closing this since it seems to be resolved with the latest Angular CLI release (1.1.0-rc.1)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duplicated Material modules in aot generaed lazy load chunk ...
I've taken a look at my (lazy load) chunk files generated by Angular CLI ( --prod so with aot) and I wonder why...
Read more >
Application is generating a chunk of my lazy load module with ...
I am unable to understand why this default ~ is getting generated. I am expecting to load modules only when one of its...
Read more >
Lazy-loading feature modules - Angular
Setting up a lazy-loaded feature module requires two main steps: Create the feature module with the Angular CLI, using the --route flag. Configure...
Read more >
angular/angular-cli - Gitter
I just checked and one of my lazy loaded module where no external lib is imported is also included in the main bundle....
Read more >
Hello World With The CLI, AoT, Lazy Loading Routes ...
Ben Nadel shares his "hello world" demo in which he gets Ahead of Time (AoT) compiling, differential loading, lazy-loading of routes, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found