react-code-blocks icon indicating copy to clipboard operation
react-code-blocks copied to clipboard

Is there a way to only load certain languages? Bundle size is large

Open jacobedawson opened this issue 5 years ago • 6 comments

Hi, react-code-blocks is very nice! However, it would be useful if there was a way to only load the required languages, as currently the bundle is very large and in most cases will be loading many more languages than the client likely needs.

jacobedawson avatar Dec 22 '20 11:12 jacobedawson

Hey @jacobedawson, that's an interesting point you bring up. Currently, the languages are called using the PrismAsyncLight component offered by react-syntax-highlighter which should optimize the build size.

But the availability of languages might be a reason for the large package size.

Perhaps we can split the packages into a light version that would require the language to be a peer dependency?

I'm open to suggestions here

rajinwonderland avatar Dec 31 '20 18:12 rajinwonderland

Yeah, I'm using react-syntax-highlighter and I'm able to require only the languages that I need, I think it makes sense since there are a lot of language files that will never be used.

jacobedawson avatar Jan 03 '21 11:01 jacobedawson

I second the request for a 'light' version with a way to select only the languages needed. I wanted a quick option for some JS highlighting and while the display looks great, my chunked build went from 10 files to 310.

insaneintenti0n avatar Jan 19 '21 20:01 insaneintenti0n

Just wanted to bump this issue. 💯 would be great to have a light build option.

hulto avatar Oct 08 '23 20:10 hulto

The prod build creates hundreds of react-syntax-highlighter_languages*.chunk.js files even though it's only using the React highlighter.

peacechen avatar Mar 06 '24 07:03 peacechen