jsx-email icon indicating copy to clipboard operation
jsx-email copied to clipboard

Dynamic import of shikiji adds 1.2Mb to gzipped bundle

Open dpeek opened this issue 1 year ago • 1 comments

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?

dpeek avatar Mar 12 '24 22:03 dpeek

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 avatar Mar 13 '24 13:03 shellscape

@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.

shellscape avatar Sep 14 '24 21:09 shellscape