Tree-shaking for production build is not working properly
See original GitHub issueBug, feature request, or proposal:
The production bundle size is not shrinking
What is the expected behavior?
Base on the new package structure the production bundle (ng build --prod) should not have included all the Material Components Module
What is the current behavior?
Base on the change log now we should create our own Custom MaterialModule, in my case I have this one:
import { NgModule } from '@angular/core';
import {
MdCardModule,
MdChipsModule,
MdToolbarModule,
MdButtonModule,
MdSidenavModule,
MdRippleModule,
MdIconModule,
MdListModule,
MdProgressSpinnerModule,
} from '@angular/material';
@NgModule({
imports: [
MdCardModule,
MdChipsModule,
MdToolbarModule,
MdButtonModule,
MdSidenavModule,
MdRippleModule,
MdIconModule,
MdListModule,
MdProgressSpinnerModule,
],
declarations: [
],
providers: [
],
exports: [
MdCardModule,
MdChipsModule,
MdToolbarModule,
MdButtonModule,
MdSidenavModule,
MdRippleModule,
MdIconModule,
MdListModule,
MdProgressSpinnerModule,
]
})
export class CustomMaterialModule { }
that is imported in the AppModule.
Even if I remove all the module and import only, for example, MdButtonModule, the size of material library in the production vendor.js still 308Kb
Which versions of Angular, Material, OS, browsers are affected?
@angular/cli: 1.0.0 node: 7.9.0 os: linux x64 @angular/animations: 4.0.1 @angular/common: 4.0.1 @angular/compiler: 4.0.1 @angular/core: 4.0.1 @angular/forms: 4.0.1 @angular/http: 4.0.1 @angular/material: 2.0.0-beta.3 @angular/platform-browser: 4.0.1 @angular/platform-browser-dynamic: 4.0.1 @angular/router: 4.0.1 @angular/cli: 1.0.0 @angular/compiler-cli: 4.0.1
Is there anything else we should know?
This is the vendor sourcemap generated by source-map-explorer
Issue Analytics
- State:
- Created 6 years ago
- Reactions:31
- Comments:51 (25 by maintainers)
Top GitHub Comments
Yep, just spent a while talking about this with the rest of the Angular core team. The gist is that the new packing structure doesn’t work out of the box with how webpack tries to eliminate dead code. We’re working on a solution and will publish a beta.4 as soon as we have a good approach.
@CardzMania just avoid importing modules from
@angular/material
:Before:
After: