diff --git a/packages/core/.nycrc.json b/.nycrc.json similarity index 100% rename from packages/core/.nycrc.json rename to .nycrc.json diff --git a/packages/core/README.md b/packages/core/README.md index 4ff5831..63e5fee 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -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 @@ -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 @@ -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"`,
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 @@ -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. diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index e41a540..2bb4b7a 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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 }