2.3 KiB
2.3 KiB
tsbundle Hints and Findings
Bundler Architecture
- tsbundle uses a child process architecture where each bundler runs in a separate process
- Configuration is passed via environment variables as JSON (IEnvTransportOptions)
- The main class
TsBundle
spawns child processes usingsmartspawn.ThreadSimple
Bundler Implementations
- esbuild (default): Fully implemented, production ready, 2.2K minified
- rolldown: Implemented and working (beta), produces smallest bundles (1.5K minified)
- rspack: Implemented and working, webpack-compatible API, 6.1K minified
- rollup: Removed (was never implemented)
- parcel: Removed (was never implemented)
Adding New Bundlers
To add a new bundler, you need:
- Update
ICliOptions
interface to include the bundler name - Add case in
getBundlerPath()
switch statement - Create
mod_<bundler>/
directory with:plugins.ts
: Import and re-export the bundlerindex.child.ts
: Implement TsBundleProcess class with buildTest() and buildProduction()
- Add bundler to package.json dependencies
Rolldown Specific Notes
- Rolldown is in beta (v1.0.0-beta.18) but working well
- API: Use
rolldown()
function directly, notrolldown.rolldown()
- Output options go in the
write()
method, not the initial config - Uses
dir
andentryFileNames
instead offile
for output (handles dynamic imports) - Includes
inlineDynamicImports: true
to avoid chunk splitting issues - Produces smaller minified bundles than esbuild (1.5K vs 2.2K in tests)
- Supports TypeScript via
resolve.tsconfigFilename
Rspack Specific Notes
- Rspack v1.3.15 - stable and production ready
- Uses webpack-compatible API (callback-based)
- Built-in SWC loader for TypeScript transpilation
- Produces larger bundles than esbuild/rolldown due to webpack runtime overhead
- Best choice if you need webpack compatibility or advanced features
- Supports ES modules output via
experiments.outputModule: true
CLI Usage
- Default bundler:
tsbundle
(uses esbuild) - Specify bundler:
tsbundle --bundler=rolldown
ortsbundle --bundler=rspack
- Production mode:
tsbundle --production
- Combined:
tsbundle --bundler=rolldown --production
Known Issues
- esbuild recently had splitting and tree-shaking disabled due to issues
- The README still mentions "a bundler using rollup" but uses esbuild by default