From 3adbee549f2fc5c4edaf1d99bb557ec7ddf23f9a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 10 Sep 2026 07:08:59 +0000 Subject: [PATCH] Make the component library tree-shakeable Importing a single component pulled the whole library into the consumer bundle: a trivial BccBadge cost 823 kB, and 785 kB arrived before any component was referenced at all. Two causes, and fixing either alone changes nothing: - dist/component-library.js was a single 2.59 MB ES module. Bundlers shake at module granularity, so with one module every top-level statement whose purity Rollup cannot prove has to be kept. PrimeVue's per-component style modules call BaseStyle.extend() and the theme preset calls definePreset() at module top level; concatenated into one file those become impure top-level statements that are unreachable but not removable. - package.json declared no sideEffects, so consumers had to assume the whole file was side-effectful. The ES build now emits one file per module (output.preserveModules) and the package declares "sideEffects": ["**/*.css"]. Dependencies are re-rooted under dist/vendor//... because npm strips node_modules directories from published tarballs and Rollup's default naming would put them there. Measured against the packed tarball, with a Vue-only baseline of 58 kB: { BccBadge } 823 kB -> 62 kB { BccBadge, BccButton, BccTag } 851 kB -> 164 kB { BccDataTable, BccColumn } 1171 kB -> 554 kB Cost is now proportional to what is imported: a Badge+Button+Tag bundle carries only the button, badge and ripple styles, no datatable or galleria. src/ is unchanged, so the public API is identical. PrimeVue deliberately stays bundled rather than external: the @primevue/icons pnpm patch that swaps in @bcc-code/icons-vue only reaches consumers through our own build output, so externalizing it would silently revert every BCC icon. preserveModules only supports the ES format, so the UMD bundle moves to its own config (vite.config.umd.ts). Its output is byte-identical to before, including the runtime