ember-prism icon indicating copy to clipboard operation
ember-prism copied to clipboard

Dynamically adding languages at runtime

Open NullVoxPopuli opened this issue 5 years ago • 5 comments

I'm trying to do this in emberclear.io, without ember-prism, but it's been tricky enough where I think once I figure it out, it should be pulled in to here.

The reasoning behind being able to dynamically load languages at runtime is to cut down on bundle size. Right now, the ember-prism config is static. Prism is large, (esp when compared to the total size of small apps). So, being able to omit everything Prism for the initial load is greatly desireable, and then once code renders that needs prism, it could fetch the deps. Also, for editor purposes (imagine slack's code snippet modal), having the list of languages selectable, but not always loaded would benefit load/parse performance as well.

NullVoxPopuli avatar Nov 03 '19 23:11 NullVoxPopuli

Totally open to this 👍

RobbieTheWagner avatar Nov 04 '19 02:11 RobbieTheWagner

I have this implemented in emberclear:

what are thoughts on this approach? the downside is that it copies all prism assets into your dist directory but, has ~1KB impact on your initially served assets (due to only being a service)

With that approach, we could get rid of the config options as well (aside from maybe theme?)

NullVoxPopuli avatar Jun 20 '20 17:06 NullVoxPopuli

@NullVoxPopuli I think we should try to keep the config static, and keep the things you don't want out of dist, while also dynamically loading the things you do want when the time is right. I think that way we can get the best of both worlds.

RobbieTheWagner avatar Jul 12 '20 16:07 RobbieTheWagner

what's the advantage of keeping additional files out of dist?

NullVoxPopuli avatar Jul 12 '20 16:07 NullVoxPopuli

what's the advantage of keeping additional files out of dist?

Just to not have extra stuff in it. I suppose it's no big deal, but just don't like putting unnecessary things in the bundle.

RobbieTheWagner avatar Jul 12 '20 16:07 RobbieTheWagner