From b0a91f8d4abc83ae06449bd7050343ba58f25b6f Mon Sep 17 00:00:00 2001 From: Shigma Date: Wed, 14 Feb 2024 01:23:06 +0800 Subject: [PATCH] docs: add setup --- packages/core/README.md | 78 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/packages/core/README.md b/packages/core/README.md index 1f7e13d..f972371 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -3,10 +3,84 @@ [![npm](https://img.shields.io/npm/v/dumble?style=flat-square)](https://www.npmjs.com/package/dumble) [![GitHub](https://img.shields.io/github/license/shigma/dumble?style=flat-square)](https://github.com/shigma/dumble/blob/master/LICENSE) -Zero-configuration bundler with TypeScript and esbuild. +Dumble is a zero-configuration bundler for your TypeScript project. -## Install +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. + +Use [esbuild](https://esbuild.github.io/) under the hood. + +## Quick Setup + +1. Install: ```sh npm install --save-dev dumble ``` + +2. Add a `build` script: + +```json +{ + "scripts": { + "build": "tsc -b && dumble" + } +} +``` + +3. Start building: + +```sh +npm run build +``` + +## Configuration + +For most scenarios, you don't need to configure anything. Below are some properties you can set in `tsconfig.json` and `package.json` to customize the build process. + +```json +// tsconfig.json +{ + "compilerOptions": { + // the input and output directories + "rootDir": "src", + "outDir": "lib", + + // if you want declaration files + "declaration": true, + "emitDeclarationOnly": true, + + // otherwise + "noEmit": true, + }, +} +``` + +```json +// package.json +{ + "name": "my-package", + + // Set "module" or "commonjs" (https://nodejs.org/api/packages.html#type) + "type": "module", + + // Define the output files + "main": "./dist/index.cjs", + "module": "./dist/index.mjs", + "types": "./dist/index.d.cts", + + // Define output files for Node.js export maps (https://nodejs.org/api/packages.html#exports) + "exports": { + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + }, + "import": { + "types": "./dist/index.d.mts", + "default": "./dist/index.mjs" + } + }, + + // bin files will be compiled to be executable with the Node.js hashbang + "bin": "./dist/cli.js", +} +```