shellscape / jsx-email

Build emails with a delightful DX
https://jsx.email
MIT License
986 stars 33 forks source link

Dynamic import of shikiji adds 1.2Mb to gzipped bundle #183

Closed dpeek closed 2 weeks ago

dpeek commented 6 months ago

Hi there! I'm using jsx-email in a serverless context (Cloudflare Workers) and noticed my bundle size jumped quite a bit after adding jsx-email. After some investigation it seems that the Code component importing shikiji is the main culprit, adding almost 8MB of uncompressed (1.2Mb gzipped) javascript to the bundle.

This isn't a blocker as I'm still below the worker size limit (although above what they recommend). Still, it seems like it would be nice to allow users to opt-out of this dependency (it's unlikely we'll need code highlighting in our emails!)

I've tried importing components individually, but I guess since renderer references them all it's impossible for them to be tree-shaken? Perhaps you could change the API so that users can pass in a highlighting function to the renderer?

shellscape commented 6 months ago

Thanks for the issue. This is a known problem that we're working on, and also impacts https://github.com/shellscape/jsx-email/issues/82. For the moment, the fix is to simply exclude shijiki (in the next major that'll be shiki) in your bundler config.

since renderer references them all

I don't believe that's the issue, but we're def working to improve tree shaking.

shellscape commented 2 weeks ago

@dpeek shiki has had a lot of work done lately, and we're going to be updating to the latest version in v2.0.0 (https://github.com/shellscape/jsx-email/pull/206). I've also pinged @antfu on X to see if there are any additional strategies that would make sense to reduce the bundling size. going to close this one for now, since there's nothing really actionable on our end at the moment.