LI

Bundling & Distribution

Package distribution, tree-shaking support, and multi-format builds for libraries

Details

Language / Topic
_UUniversal
Category
Tooling

Rules

balanced
- Use the `package.json` `exports` field to define public entry points and prevent consumers from importing internal modules.
- Ship both ESM and CJS formats. Use `main` for CJS, `module` for ESM, and `exports` for modern bundlers.
- Use the `package.json` `exports` field to define public entry points. Prevent consumers from importing internal modules with explicit path restrictions.
- Monitor and enforce published package size. Use `size-limit` or `bundlephobia` in CI. Alert on significant increases.
- Mark heavy optional features as peer dependencies so consumers install them only when needed.
- Provide sub-path exports for large libraries: `import { Button } from 'my-lib/button'` — so consumers can import only what they need.
- Test the published package by installing it from a tarball (`npm pack`) in a clean project. Verify imports, types, and runtime behavior.
- Exclude tests, fixtures, docs, and source maps from the published package. Use `.npmignore` or the `files` field to allowlist only production files.