Skip to content

Commit

Permalink
docs: entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 17, 2024
1 parent 838607d commit 37962bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
File renamed without changes.
44 changes: 25 additions & 19 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Dumble is a zero-configuration bundler for your TypeScript project.

It automatically reads `tsconfig.json` and `package.json` to determine what files to bundle, which is the desired format, where to output the files, and more.

Inspired by [pkgroll](https://github.com/privatenumber/pkgroll).

Use [esbuild](https://esbuild.github.io/) under the hood.

## Quick Setup
Expand All @@ -27,6 +29,8 @@ npm install --save-dev dumble
}
```

Note: `dumble` is intended to be used together with `tsc` (TypeScript compiler). `tsc` is useful for type checking and generating `.d.ts` files, while `dumble` is used for bundling and tree-shaking `.js` files.

3. Start building:

```sh
Expand Down Expand Up @@ -95,31 +99,33 @@ For most scenarios, you don't need to configure anything. Below are some propert

### Entry Points and Exports

| `package.json` property | Output Format |
| --- | --- |
| main | auto-detected |
| module | esmodule |
| types | declaration |
| exports.* | auto-detected |
| exports.*.require | commonjs |
| exports.*.import | esmodule |
| bin | auto-detected |

Auto-detection is based on the extension and the [`type`](https://nodejs.org/api/packages.html#type) field in `package.json`:

| Extension | Type |
| --- | --- |
| `.cjs` | commonjs |
| `.mjs` | esmodule |
| `.js` | esmodule if `type` is `"module"`, <br>commonjs otherwise |

### Dependency bundling

Packages to externalize are detected by reading dependency types in package.json. Only dependencies listed in devDependencies are bundled in.

When generating type declarations (.d.ts files), this also bundles and tree-shakes type dependencies declared in devDependencies as well.

```json5
// package.json
{
"peerDependencies": {
// Externalized
},
"dependencies": {
// Externalized
},
"optionalDependencies": {
// Externalized
},
"devDependencies": {
// Bundled
},
}
```
## Advanced Usage

## Advanced Features
## Other Features

### Target

Expand All @@ -129,6 +135,6 @@ When generating type declarations (.d.ts files), this also bundles and tree-shak

## Credits

[pkgroll](https://github.com/privatenumber/pkgroll) is a similar project with more features, such as `--watch` and rollup minification (which can generate smaller files than esbuild in some cases). If you find dumble lacking in some way, consider using pkgroll instead (better yet, open an issue or pull request to improve dumble).
[pkgroll](https://github.com/privatenumber/pkgroll) is a similar project with more features, such as `--watch` and rollup minification (which can generate smaller files than esbuild in some cases). If you find dumble not satisfying your needs, consider using pkgroll instead (better yet, open an issue or pull request to improve dumble).

Compared to pkgroll, dumble is simpler and more focused on zero-configuration. Also, dumble can be easily integrated into a monorepo with multiple packages, and can be further customized with esbuild options.
4 changes: 3 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const externalPlugin = ({ cwd, manifest, exports }: dumble.Data): Plugin => ({
: args.path.split('/', 1)[0]
if (name === manifest.name) return { external: true }
const types = new Set(DependencyType.filter((type) => manifest[type]?.[name]))
if (types.size === 0) throw new Error(`Missing dependency: ${name}`)
if (types.size === 0) {
throw new Error(`Missing dependency: ${name} from ${args.importer}`)
}
// devDependencies are bundled
types.delete('devDependencies')
return { external: types.size > 0 }
Expand Down

0 comments on commit 37962bf

Please sign in to comment.