PrimeNG Component Imports: Unresolved Primeicons Tree‑Shaking Behavior
0 reputation · 02 May 2023, 22:01 UTC
Goal
The objective is to reduce the production bundle size for a low‑traffic Angular application that only uses a handful of PrimeNG components (e.g., ButtonModule, MenuModule). By importing components via ES module entry points (v13+), Angular’s build optimizer can tree‑shake unused PrimeNG code. However, the peer dependency primeicons remains in the bundle because its CSS font and stylesheet are not tree‑shakable.
Constraints & Uncertainty
Primeicons distributes a single CSS font file and stylesheet; its package.json lacks a sideEffects: false flag and does not expose individual icon modules. Consequently, any component that references icon CSS classes (e.g., Button icon="pi pi-user") causes the entire icon set to be bundled. This overhead (~30 KB minified + font) can dominate the final bundle when only a few components are used. The PrimeNG team has acknowledged this limitation but has not provided a migration path to a tree‑shakable icon system.
Unresolved Decision
How can the build process be configured to exclude or reduce the primeicons payload when only a subset of icon‑dependent components is imported, without forcing developers to manually override icon classes in every component instance?
Specific Questions
- Is there a supported Angular or PrimeNG configuration that can exclude primeicons CSS and font files from the production bundle when only a subset of icon‑dependent components is used?
- Can primeicons be replaced with a custom SVG icon set that is tree‑shakable, and if so, what is the recommended approach to avoid per‑component overrides?
- Does the latest PrimeNG release (v17+) expose a tree‑shakable icon module or alternative icon strategy that mitigates the current bundle size overhead?