Keep Chart.js and the whole of lodash out of apps' initial bundle

Each chart registers what it needs when it is built instead of on
import, and lodash is imported one function at a time. In TaskStream
the initial bundle drops from 2.13 MB to 1.90 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 20:21:40 +02:00
parent 53d78cc7a1
commit 499f8ac075
13 changed files with 43 additions and 43 deletions

View File

@@ -184,11 +184,21 @@ Detalles a tener en cuenta:
- **`Dataset.cubicInterpolationMode` pasa a opcional.** Solo tiene sentido en
`line`; forzarlo en `bar`/`pie`/`doughnut` no aportaba nada y esos tipos ni
siquiera usan `Dataset` (los dos últimos usan `ChartSlice`).
- **Cada gráfico registra lo suyo en `buildChart()`, no al importar.** El
paquete es un único `fesm`, así que un `Chart.register(...)` a nivel de
módulo se ejecutaba en cualquier app que importase `@pi/ui` y metía Chart.js
entero en su bundle inicial, pintase gráficos o no (en TaskStream, unos
230 kB). Registrar dos veces lo mismo no hace nada. Si se añade un tipo de
gráfico, su registro va ahí también.
- **El `type="bar"` del `pi-chart` original nunca funcionó**: el input
existía pero `getLineChartConfigs()` construía siempre un chart `line`
ignorando su valor. Se descubrió al dividir los componentes; `pi-bar-chart`
es la primera versión que realmente renderiza barras.
**`lodash` se importa por función** (`lodash/isEqual`, `lodash/some`,
`lodash/capitalize`), nunca `import _ from 'lodash'`: lodash es CommonJS y el
import completo mete la librería entera en el bundle de quien use un select.
**El loader de servidor de traducciones ya no está en el barrel.**
`util/translate/loaders/translate-server.loader` usa `fs`, `path` y `process`;
exportarlo desde `@pi/ui` rompía el bundle de navegador de cualquier app que