Web components
@munsonlabs/video-player/element registers <ml-video-player>, <ml-video-card>, <ml-video-stage>, <ml-video-placeholder>, <ml-video-hide-marker>, and a control per piece such as <ml-video-play-button>. Every tag reads vendor, then package, then part, so nothing this package registers can collide with another @munsonlabs package.
| Bundle | Includes | Auto-injects CSS |
|---|---|---|
/element | Player tags + all 13 controls | /style |
/element/core | Player tags only | none - import /style/core |
/element/controls | The 13 controls only | none - import /style/controls |
customElements.define() throws.Loading without a build step
Vue is an external dependency of every element bundle, and /element and /element/core also reach for hls.js and dashjs through a bare dynamic import() when an HLS or DASH source mounts. /element/controls needs neither, since it ships no adapter. How much setup that costs you depends entirely on where you load the bundle from.
From esm.sh, it costs one line. esm.sh rewrites every bare specifier to its own URLs - vue, hls.js and dashjs alike - so no import map is needed at all:
<script>
globalThis.__VUE_PROD_DEVTOOLS__ = false
</script>
<script type="module">
import 'https://esm.sh/@munsonlabs/video-player/element'
</script>
That global is unavoidable and must sit in its own <script>, not the module below - import is hoisted, so setting it there would run after Vue had already read it and failed silently. Vue's esm-bundler build expects a bundler to substitute this compile-time flag; nothing does that on a CDN, and without it every element registers but renders nothing. Vue fills in the other two flags itself.
Supplying your own Vue - because you already have one on the page and don't want a second copy - means opting out of that rewriting with ?external=vue, and then resolving bare vue yourself. An esm-browser build has the flags already substituted, so the global is no longer needed:
<script type="importmap">
{
"imports": {
"vue": "https://unpkg.com/vue@3/dist/vue.runtime.esm-browser.prod.js",
"@munsonlabs/video-player/element": "https://esm.sh/@munsonlabs/video-player/element?external=vue"
}
}
</script>
<script type="module">
import '@munsonlabs/video-player/element'
</script>
?external=vue externalises only Vue - without it, a bare vue import map entry is never consulted, since esm.sh has already rewritten the specifier to its own URL. hls.js and dashjs stay resolved by esm.sh either way.
Self-hosting, or loading raw files from unpkg/jsdelivr paths, serves the bundle byte for byte with every bare specifier intact - so all three need mapping, plus the flag if your Vue build needs it:
<script type="importmap">
{
"imports": {
"vue": "https://unpkg.com/vue@3/dist/vue.runtime.esm-browser.prod.js",
"hls.js": "https://cdn.jsdelivr.net/npm/hls.js@1/+esm",
"dashjs": "https://cdn.jsdelivr.net/npm/dashjs@4/+esm"
}
}
</script>
Skip hls.js/dashjs only if you're certain no .m3u8 or .mpd source will ever mount - the failure is deferred until one does, not caught at load.
import '@munsonlabs/video-player/element' is the whole setup.Adapters load on demand
/element and /element/core import() a platform's adapter only once a URL for it mounts, from a sibling chunks/ directory - a page playing only MP4/HLS/DASH downloads none of them. These are relative paths, not bare specifiers, so they need no import map entry: a directory-serving CDN (unpkg, jsdelivr, esm.sh) handles them, and self-hosting means deploying chunks/ next to the bundle.