paulirish / lite-youtube-embed

A faster youtube embed.
https://paulirish.github.io/lite-youtube-embed/
Other
5.84k stars 271 forks source link

Offering the class in ESM format #181

Closed davidsneighbour closed 1 month ago

davidsneighbour commented 4 months ago

I would love to add this to a more modern usage with webpack, tree shaking and "all the fancy gimmicks". For that to work the class would need to be exported and we run the initialization in our own scripts. For instance, in lite-yt-embed.js remove customElements.define('lite-youtube', LiteYTEmbed); and add

export default LiteYTEmbed

and in the using script import it and initialize it

import {LiteYTEmbed} from `lite-youtube-embed`
customElements.define('lite-youtube', LiteYTEmbed);

That would require a type: module in package.json and "main": "path to lite-yt-embed.js" so the module resolves the script properly.

I am sure it can be possible to keep the current setup for older users and add ESM functionality.

Would you consider that?