Skip to content

Commit

Permalink
docs: quick start
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 17, 2023
1 parent 5784277 commit f9794fd
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@

Bunchee makes bundling your library into one file effortless, with zero configuration required. It is built on top of Rollup and SWC ⚡️, allowing you to focus on writing code and generating multiple module types (CommonJS, ESModules) simultaneously.

## Installation
## Quick Start

### Installation

```sh
npm install --save-dev bunchee
```

Create your library
### Configuration

Create your library entry file and package.json.
```sh
cd ./my-lib && mkdir src
touch ./src/index.ts
touch package.json
```

Configure module exports

[exports sugar in Node.js](https://nodejs.org/api/packages.html#exports-sugar)

You can use the `exports` field to support different conditions and leverage the same functionality as other bundlers, such as webpack. The exports field allows you to define multiple conditions.

Then use use the [exports field in package.json](https://nodejs.org/api/packages.html#exports-sugar) to configure different conditions and leverage the same functionality as other bundlers, such as webpack. The exports field allows you to define multiple conditions.
```json
{
"exports": {
Expand All @@ -48,19 +46,22 @@ You can use the `exports` field to support different conditions and leverage the
}
```

Using pure ESM package?

If you want to use ESM package, change the `type` field in package.json to `module`, `bunchee` will change the output format to ESM.
```json
{
"type": "module",
"main": "./dist/index.mjs",
"exports": {
"import": "dist/index.mjs",
"require": "dist/index.cjs"
},
"scripts": {
"build": "bunchee"
}
}
```

Then just run `npm run build`, or `pnpm build` / `yarn build` if you're using these package managers. The output format will based on the exports condition and also the file extension. Given an example:
Now just run `npm run build` (or `pnpm build` / `yarn build`) if you're using these package managers, `bunchee` will find the entry files and build them.
The output format will based on the exports condition and also the file extension. Given an example:

- It's CommonJS for `require` and ESM for `import` based on the exports condition.
- It's CommonJS for `.js` and ESM for `.mjs` based on the extension regardless the exports condition. Then for export condition like "node" you could choose the format with your extension.
Expand Down

0 comments on commit f9794fd

Please sign in to comment.