Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: switch to dual package emitting #2746

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Building

We are using [tsup](https://tsup.egoist.dev/) and [esbuild](https://esbuild.github.io/) together with [Microbundle](https://www.npmjs.com/package/microbundle) to build our component library.

Each component builds to its own `dist` directory with:

- `index.d.ts` – TypeScript type declaration file
- `index.js` – CJS (CommonJS)
- `index.modern.mjs` – [Modern](https://github.com/developit/microbundle#-modern-mode-) output (work in all modern browsers)
- `index.module.js` – legacy ESM (ES Modules) output (for bundlers)
- `index.umd.js` – legacy UMD (Universal Module Definition) output (for Node & CDN use)

## Create a build of the library

```bash
npm run-script build
```

## v5 alpha/beta pre-releases

> [!WARNING]
>
> Revisit the build setup before the v5 release

We aim to emit ESM only in our next major release.

Until then, we emit CJS and ESM using a dual-package approach with `tsc` and [tsconfig-to-dual-package](https://github.com/azu/tsconfig-to-dual-package/tree/main).

This ensures Node/TypeScript point to the right package type (commonjs, module) depending on the consumer's configuration, without the hassle of us to "hack" the main `package.json` and `tsconfig` to satisfy all use cases.

The build has the following structure in its own `dist` directory:

- `./cjs` – CJS (CommonJS) with declaration + inline source map.
- `./esm` – ESM (ES Modules) with declaration + inline source map.
Loading