Loading lit from Skypack

Lit 2 stable was released today, offering a tiny, feature-full framework for constructing web components using modern JavaScript.

The getting started documentation involves a whole lot of npm usage, but I wanted to just drop something into an HTML page and start trying out the library, without any kind of build step.

After some discussion on Twitter and with the help of @WestbrookJ I figured out the following pattern, which loads code from Skypack:

<script type="module">
import { LitElement, html } from 'https://cdn.skypack.dev/lit';
  
class MyEl extends LitElement {
  render() {
    return html`Hello world!`
  }
}
customElements.define('my-el',MyEl);
</script>
<my-el></my-el>

Also relevant: lit-dist.

Created 2021-09-21T18:03:21-07:00, updated 2021-11-21T16:44:18-08:00 · History · Edit