https://github.com/developit/microbundle-2
https://github.com/developit/microbundle-2
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/developit/microbundle-2
- Owner: developit
- Created: 2024-07-19T17:48:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-14T15:57:54.000Z (10 months ago)
- Last Synced: 2025-04-14T03:14:42.227Z (9 months ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 41
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Microbundle 2
What if microbundle could figure out how to bundle your library based on the `"exports"` field you already have to define in your package.json?
And what if it was also absurdly fast, and one 500kb file with a single native dependency?
```sh
npm i -g microbundle-2
# or
npx microbundle-2
```
This is a reimplementation of [Microbundle](https://github.com/developit/microbundle)
built on [ESBuild](https://esbuild.github.io).

## Simple Example
You write a package.json that looks like this:
```jsonc
{
"name": "simple",
"type": "module",
"exports": {
"import": "./dist/lib.js",
"default": "./dist/lib.cjs"
}
}
```

## Multiple entries
Just define your package exports the way you already have to for Node/Vite/etc:
```jsonc
{
"name": "multi-entry",
"type": "module",
"exports": {
".": {
"types": "./dist/lib.d.ts",
"import": "./dist/lib.js",
"default": "./dist/lib.cjs"
},
"./a": {
"types": "./dist/a.d.ts",
"import": "./dist/a.js",
"default": "./dist/a.cjs"
},
"./b": {
"types": "./dist/b.d.ts",
"import": "./dist/b.js",
"default": "./dist/b.cjs"
}
}
}
```

This example has a dynamic import, which you can see produced a `./c` chunk. Both the ESM and CJS versions work the same way!
## Wildcards/patterns
Wildcard/pattern exports are also supported:
```jsonc
{
"name": "patterns",
"type": "module",
"exports": {
".": {
"types": "./build/index.d.ts",
"import": "./build/index.js",
"default": "./build/index.cjs"
},
"./lib/*": {
"types": "./build/lib/*.d.ts",
"import": "./build/lib/*.js",
"default": "./build/lib/*.cjs"
},
"./components/*": {
"source": "./lib/components/*.tsx",
"types": "./build/components/*.d.ts",
"import": "./build/components/*.js",
"default": "./build/components/*.cjs"
}
}
}
```
