|
| 1 | +# Bunchee - A Zero-config JavaScript Bundler |
| 2 | +bunchee is a zero-config JavaScript bundler designed to create optimized Node.js and browser-friendly packages. It focuses on simplicity, speed, and developer-friendly defaults, making it an excellent choice for bundling modern JavaScript libraries. |
| 3 | + |
| 4 | +## Key Features |
| 5 | +- **Zero Configuration**: Bundles projects with sensible defaults out of the box. |
| 6 | +- **Tree Shaking**: Removes unused code to produce smaller bundles. |
| 7 | +- **TypeScript Support**: Handles `.ts` and `.tsx` files seamlessly. |
| 8 | +- **ESM and CJS Outputs**: Generates dual modules to support modern and legacy environments. |
| 9 | +- **Source Maps**: Includes inline or external source maps for easier debugging. |
| 10 | +- **CSS/JSON Asset Bundling**: Automatically processes non-JavaScript assets for compatibility. |
| 11 | +- **Fast Build Times**: Built with optimized tooling for rapid iteration. |
| 12 | + |
| 13 | +## Installation |
| 14 | +Install bunchee as a development dependency in your project: |
| 15 | +```bash |
| 16 | +npm install --save-dev bunchee |
| 17 | +``` |
| 18 | + |
| 19 | + |
| 20 | +## Usage |
| 21 | +### Build |
| 22 | +Build a project: |
| 23 | +```sh |
| 24 | +mkdir src && touch ./src/index.ts && touch package.json |
| 25 | +``` |
| 26 | + |
| 27 | +Add the exports in `package.json`. |
| 28 | +```json |
| 29 | +{ |
| 30 | + "name": "coffee", |
| 31 | + "type": "module", |
| 32 | + "main": "./dist/index.js", |
| 33 | + "scripts": { |
| 34 | + "build": "bunchee" |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +Run build: |
| 40 | +```sh |
| 41 | +npm run build |
| 42 | +``` |
| 43 | + |
| 44 | +### CLI |
| 45 | +Bundle a JavaScript or TypeScript entry file: |
| 46 | +```bash |
| 47 | +bunchee src/index.js --output dist/bundle.js |
| 48 | +``` |
| 49 | + |
| 50 | +### API |
| 51 | +Use bunchee programmatically in your Node.js scripts: |
| 52 | +```javascript |
| 53 | +const bunchee = require('bunchee'); |
| 54 | + |
| 55 | +bunchee.bundle({ |
| 56 | + input: 'src/index.js', |
| 57 | + output: 'dist/bundle.js', |
| 58 | +}); |
| 59 | +``` |
| 60 | + |
| 61 | +## Example Configuration |
| 62 | +Although bunchee requires no config, you can customize options via CLI flags or programmatically: |
| 63 | +- Specify input and output files |
| 64 | +- Enable/disable source maps |
| 65 | +- Choose output formats (ESM, CJS) |
| 66 | + |
| 67 | +## Contributions |
| 68 | +Contributions are welcome! Check out the repository's [issues](https://github.com/huozhi/bunchee/issues) and [contributing guidelines](https://github.com/huozhi/bunchee/blob/main/CONTRIBUTING.md) for more information. |
| 69 | + |
| 70 | +## License |
| 71 | +bunchee is open-source and available under the [MIT License](https://github.com/huozhi/bunchee/blob/main/LICENSE). |
0 commit comments