Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge Bundle Size when import every module #4686

Open
alexnoise79 opened this issue Mar 21, 2024 · 7 comments
Open

Huge Bundle Size when import every module #4686

alexnoise79 opened this issue Mar 21, 2024 · 7 comments

Comments

@alexnoise79
Copy link
Contributor

alexnoise79 commented Mar 21, 2024

Bug description:

dist bundle includes every module when a single module in included.

var NGB_MODULES = [NgbAccordionModule, NgbAlertModule, NgbCarouselModule, NgbCollapseModule, NgbDatepickerModule, NgbDropdownModule, NgbModalModule, NgbNavModule, NgbOffcanvasModule, NgbPaginationModule, NgbPopoverModule, NgbProgressbarModule, NgbRatingModule, NgbScrollSpyModule, NgbTimepickerModule, NgbToastModule, NgbTooltipModule, NgbTypeaheadModule];

is present in the main-[hash].js when importing a single module in a standalone component.

Minimal reproduction

  • create a new project
  • [optional] use optimization: false in the production configuration (if you want to see the name of the bundles)
  • run ng add @ng-bootstrap/ng-bootstrap
  • remove everything from the app component (ts,html)

app.component.ts

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [
    NgbToast,
    NgbToastHeader
  ],
  templateUrl: './app.component.html'
})
export class AppComponent {
}

app.component.html

<ngb-toast></ngb-toast>
  • run command ng build your-project
  • open the dist folder and check the main bundle

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 17.2
ng-bootstrap: 16.0.0
Bootstrap: 5.3.2

@jnizet
Copy link
Member

jnizet commented Mar 22, 2024

Hi @alexnoise79

OK, but the point of optimization: true is precisely to avoid having such huge bundles, and to remove what isn't actually used by the application.
Isn't it a bit weird to opt out of the mechanism designed to reduce bundle sizes and then be surprised about getting a big bundle size?

@alexnoise79
Copy link
Contributor Author

alexnoise79 commented Mar 22, 2024

Hi @jnizet

yes i l know, but is the only way to see all the module names

in any case even with optimization:false the bundle still contains all the modules, and this is wrong.

i updated the description, thanks

@jnizet
Copy link
Member

jnizet commented Mar 22, 2024

It's not wrong. The optimization is precisely designed to tree-shake the bundles and remove the unused parts.
I don't understand what you mean by "is the only way to see all the module names".

@alexnoise79
Copy link
Contributor Author

@jnizet

var NGB_MODULES = [NgbAccordionModule, NgbAlertModule, NgbCarouselModule, NgbCollapseModule, NgbDatepickerModule, NgbDropdownModule, NgbModalModule, NgbNavModule, NgbOffcanvasModule, NgbPaginationModule, NgbPopoverModule, NgbProgressbarModule, NgbRatingModule, NgbScrollSpyModule, NgbTimepickerModule, NgbToastModule, NgbTooltipModule, NgbTypeaheadModule];

@jnizet
Copy link
Member

jnizet commented Mar 22, 2024

That is part of the unoptimized bundle. If you turn optimization on, it will be removed. That's what optimization is for.

@alexnoise79
Copy link
Contributor Author

@jnizet

you are right, i checked the minified does not contain all, even if in some scenario i have "ngbDropdown" that have not been imported in other modules.

there is no way to tree-shake the unoptimized bundle?

@PieterjanDeClippel
Copy link

This is because the library has only a single entrypoint. For libraries ng-packagr will always produce chunks per entrypoint, and so loading a single module from this entrypoint drags the entire entrypoint into the bundle.

Some time ago I asked about this on StackOverflow, but still investigated everything myself. The library should be structured like this with entrypoints next to the src folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants