1.7 KiB
1.7 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
- rolldown: Implemented and working (beta), produces smaller bundles than esbuild
- rollup: Empty module directory exists but not implemented
- parcel: Empty module directory exists but not 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 - Produces smaller minified bundles than esbuild (1.5K vs 2.2K in tests)
- Supports TypeScript via
resolve.tsconfigFilename
CLI Usage
- Default bundler:
tsbundle
- Specify bundler:
tsbundle --bundler=rolldown
- 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