$ show developit/microbundle
Microbundle is a zero-configuration bundler for small JavaScript/TypeScript libraries, built on top of Rollup. It automatically generates multiple output formats (ESM, CJS, UMD, and a modern ES2017 bundle) from a single source entry, using package.json fields to determine input and output paths. The system reads the package.json, resolves entry points, and creates Rollup configurations for each format, applying Babel for transpilation (with custom presets for modern vs legacy targets), TypeScript via rollup-plugin-typescript2, CSS handling via PostCSS, and minification via Terser. It supports features like JSX, CSS Modules, property mangling, build-time constant replacement, module aliasing, Web Workers, and bundle visualization. The architecture is a CLI tool (`src/cli.js`) that parses arguments with `sade` and calls the core `microbundle()` function (`src/index.js`), which orchestrates the build pipeline. The codebase is well-structured, with reusable utility modules for option normalization, Babel plugin customization, and size reporting. While the dependency versions are somewhat dated (Rollup 2, Babel 7.12), the project remains actively maintained with recent commits and a comprehensive test suite covering many edge cases.
The LLM identified 3 files worth highlighting for reuse:
A Babel plugin that transforms rest parameters (e.g., `...args`) into `[].slice.call(arguments, offset)` for performance. It handles both inline replacement and variable binding, and supports arrow function conversion. This is a self-contained, reusable Babel plugin that demonstrates advanced AST manipulation and can be extracted for use in other build pipelines.
Provides utility functions for parsing CLI arguments like `--define`, `--globals`, and `--alias` into structured objects. It handles type coercion (booleans, numbers, strings, expressions) and supports the `@` prefix for expression replacement. These functions are self-contained and reusable for any CLI tool that needs similar argument parsing logic.
Computes gzip and brotli compressed sizes of build output files and formats them with color-coded output (green/yellow/red based on size thresholds). It uses `gzip-size` and `brotli-size` libraries and returns a human-readable string. This module is self-contained and can be reused in any build tool or script that needs to report compressed sizes.