Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Re-export only the symbols actually used from a bundler entry module
When a module exists purely as a build/code-splitting entry point re-exporting a library, export only the specific symbols the app actually uses rather than `export *` — a wildcard re-export pins the entire library's exports against tree-shaking.
Bad example
| 1 | // vendor/chart-lib.ts — build entry point |
| 2 | export * from 'chart-library'; |
Explanation (EN)
Re-exporting everything makes the entry's public surface the whole library, so bundlers can't tree-shake anything the app doesn't actually import from it.
Objašnjenje (HR)
Ponovnim izvozom svega, javna površina entry modula postaje cijela biblioteka, pa bundler ne može ukloniti (tree-shake) ono što aplikacija zapravo ne koristi.
Good example
| 1 | // vendor/chart-lib.ts — build entry point |
| 2 | export { createChart } from 'chart-library'; |
Explanation (EN)
Exporting only what's actually used keeps the entry honest about the library's real runtime surface and lets unused exports be dropped.
Objašnjenje (HR)
Izvozom samo onoga što se koristi, entry modul realno prikazuje stvarnu upotrebu biblioteke, a neiskorišteni izvozi mogu se ukloniti.