egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.48k stars 209 forks source link

Add option to disable ES transforms in `sucrase` #1087

Open Mrtenz opened 4 months ago

Mrtenz commented 4 months ago

tsup uses sucrase to transpile ESM to CJS when code splitting is enabled:

https://github.com/egoist/tsup/blob/83c7c7f3131ca6d46aaad4de3111c2fd5e5b5c21/src/plugins/cjs-splitting.ts#L21-L31

Unfortunately there is no way right now to specify the settings for sucrase. In our case, we wanted to disable the optional chaining polyfill that sucrase adds, since it's problematic for static analysis. The only way to do so seems to be by setting disableESTransforms: true in the options. It would be great if tsup had an option to set this.

Upvote & Fund

Fund with Polar

FrederikBolding commented 4 months ago

To be clear, @Mrtenz and I are willing to submit a PR for this feature. But we would need some guidance on how best to implement it. E.g. should we simply add a configuration option for this or automatically determine the value of disableESTransforms by looking at the target?