7 Tools for Developing Web Components in 2019
Tags: webdev, javascript, html, css
Published: 2019-09-12 14:09:14

###Web components in the wild: from lit-html to Stencil, Svelete and beyond.


So lately there’s been [much buzz around web-components](https://blog.bitsrc.io/9-web-component-ui-libraries-you-should-know-in-2019-9d4476c3f103). Here’s the gist of why: Components and widgets that build on the Web Component standards, will work across modern browsers, and can be used with any JavaScript library or framework that works with HTML.

This means more reuse, better stability, abstraction and standardization, less work and pretty much everything else that comes with better modularity. While many people are sitting around waiting on projects like [web-assembly](https://webassembly.org/), in the past year we see new tools and techs rise to bring the future today.

So, in this post, I’ll review 5 **unranked** tools you should know and consider if you’re thinking one putting web components to use in 2019. This list is only the beginning, so please, feel free to comment and suggest your own tools!

Let’s dive in.

## 1. Bit

{% youtube E5lgoz6-nfs %}

[Bit](https://bit.dev) is a platform and an [open-source tool](https://github.com/teambit/bit) built to help build modular apps through the development and composition of components.


[Bit](https://bit.dev) has some innovative key features to unlock better component modularity and reusability, which are a match-made-in-heaven with the agnostic and reusable nature of web components.

First, it automatically defines the component’s entire dependency graph to seamlessly isolate if from the project. You can individually publish multiple components from a project with one command and zero refactoring (!).

Second, and this is the really cool part, in addition to installing each component with NPM/Yarn, you can use Bit to bring a component into a new project- and develop it there to change the source code, play with styles or changes anything else as needed. No more waiting on PRs.

Third, Bit manages both the source code and dependency graph of components across projects. This is a big statement, and it’s a key to resuing components at any scale in multiple projects. You can sync changes to components across your codebase with one command, and know exactly which dependencies are changed and where. That’s extremely useful for gradual refactoring, and for making maintenance much less painful.

Finally, all the components from the repo can be shared to bit.dev (Bit hub), where they are organized in visual “playlist” like collections so your team can quickly share, discover and reuse components.

Here’s an example [wired-elements web components](https://github.com/wiredjs/wired-elements) library. Note that every component is even available to play-within a live playground before using it.


![wired-elements web components with bit](https://cdn-images-1.medium.com/max/2678/1*-2-1d7QNyXmJePAfi3l4yQ.png)*wired-elements web components with bit*

Bit speeds modular app development with components so that it is easier to maintain your codebase (e.g. gradual refactoring with full control), helps increase test-coverage and boost code reusability while allowing evolution.


## 2. lit-html and lit-element

{% youtube ruql541T7gc %}

[Lit-html](https://github.com/Polymer/lit-html) is basically a customizable construction kit for web components. It’s “An efficient, expressive, extensible HTML templating library for JavaScript”. Meaning, Lit-html uses JavaScript template strings to create dynamic templates with [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) ([example](https://coryrylan.com/blog/building-web-components-with-lit-html)).

lit-html uses fast platform features like HTML ``<template>`` elements with native cloning to boost efficiency, and only ever updates the parts of templates that actually change — it doesn’t re-render the entire view. That’s pretty fast.

![](https://cdn-images-1.medium.com/max/2000/1*0PBdQh15FPXWkayQ_9cbmw.png)

Templates are values ( strings, DOM nodes, heterogeneous lists, nested templates etc) that can be computed, passed to and from functions and nested. Expressions are JavaScript and can include what’d needed.

Directives customize how values are handled, allowing for asynchronous values, efficient keyed-repeats, error boundaries, and more.

[Lit-element](https://lit-element.polymer-project.org/) is a “simple base class for creating fast, lightweight web components”. It uses [lit-html](https://lit-html.polymer-project.org/) to render into the element’s [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) and adds API to help manage element properties and attributes. LitElement reacts to changes in properties and renders declaratively using lit-html.

![](https://cdn-images-1.medium.com/max/2000/1*AUDzy_ZQHzmPur2UKh8lbA.png)

As LitElement makes it easy to define Web Components for sharing elements across your organization or building a UI design system, it’s a very powerful combination with [Bit](https://bit.dev)- to easily create, reuse, manage and sync components. Bit’s platform will even visualize the components, so your bit collection is more than a set of reusable components- it’s a **visual design system of components** you can share, use and develop anywhere!

[Polymer/lit-html](https://github.com/Polymer/lit-html)

## 3. StencilJS

{% youtube ZmIMtgwyj90 %}

Created by the Ionic team, [Stencil](https://github.com/ionic-team/stencil) is a “web Component compiler for building fast, reusable UI components and Progressive Web Apps”. Meaning, it’s a compiler for generating Web Components and progressive web apps (PWA).

It uses TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline, and lazy-loading to generate standards-based Web Components that run on [modern and legacy browsers](https://github.com/ionic-team/stencil#browser-support).

Stencil also unlocks new capabilities for Web Components, such as Server Side Rendering without the need to run a headless browser, pre-rendering, and objects-as-properties (instead of just strings). Creating components is easy, as Stencil components are plain ES6/TypeScript classes with some decorator metadata. [Take a look](https://github.com/ionic-team/stencil)

## 4. Svelte JS

{% youtube qqt6YxAZoOc %}

[Svelte](https://github.com/sveltejs/svelte) is “a compiler that takes your declarative components and converts them into efficient JavaScript that surgically updates the DOM” when the state of your application changes. Meaning, you can build boiler-plate free components using CSS, HTML and pure JavaScript, and Svelt will compile it into small and lightweight JS with built-in reactivity.

![](https://cdn-images-1.medium.com/max/2000/1*m8HKVRmw3B2vrg1bb6zaSQ.png)

Sounds mind-blowing and simple and the same time, right? Another useful ability is the [built-in support](https://svelte.dev/blog/svelte-css-in-js) for any framework-agnostic CSS in JS library.

![](https://cdn-images-1.medium.com/max/2358/1*BkL6FPv_LmfcWJXTx7wSCQ.png)

Svelte is a major step towards framework-agnostic web components, and its workflow enables gradual refactoring which is very useful in this aspect. Combing Svelete with Bit means having a toolbox of framework-agnostic components you can easily use anywhere, and even build styling components to style other components, turning styling into a manner of composition.

[sveltejs/svelte](https://github.com/sveltejs/svelte)

## 5. Angular elements

<center><iframe width="560" height="315" src="https://www.youtube.com/embed/4u9_kdkvTsc" frameborder="0" allowfullscreen></iframe></center>

[Angular elements](https://angular.io/guide/elements) is a new package in Angular that helps us [publish Angular components as custom elements](https://blog.bitsrc.io/using-angular-elements-why-and-how-part-1-35f7fd4f0457). It does this by taking the Angular component and compiling it into a web component.

This prominent attempt to bridge the framework-agnostic gap from the framework’s end is very interesting, as the @angular/elements package exports a [createCustomElement](https://angular.io/api/elements/createCustomElement)() API that provides a bridge from Angular's component interface and change detection to the built-in DOM API.

Practically, you can use the new[createCustomElement](https://angular.io/api/elements/createCustomElement)() function to convert a component into a class and register it in the browser as a custom element. Then, you can use the new element just like a built-in HTML element in content that you add directly into the DOM. This adds new capabilities to your NG workflow, from better separation of concerns and reusability to SSR!

![](https://cdn-images-1.medium.com/max/2000/1*wI2wCqw0DIRvTzWqs2lDeQ.png)

## 6. Hybrids

**Hybrids** is a “UI library for creating [Web Components](https://www.webcomponents.org/), which favors plain objects and pure functions over class and this syntax”. It provides simple and functional API for creating custom elements.

It provides a declarative way for creating custom elements. It is a mix of functional and object-oriented architecture with a unique approach for defining custom elements. Here’s an example which relays on three property-related ideas: [descriptors](https://github.com/hybridsjs/hybrids/blob/master/docs/core-concepts/descriptors.md), [factories](https://github.com/hybridsjs/hybrids/blob/master/docs/core-concepts/factories.md) and [translation](https://github.com/hybridsjs/hybrids/blob/master/docs/core-concepts/translation.md). The library uses change detection and cache mechanism to simplify the lifecycle of the component.

    import { define } from 'hybrids';

    const MyElement = {
      count: 0,
      render: ({ count }) => {...},
    };

    define('my-element', MyElement);

“Bonus” features include a template engine based on tagged template literals and hot module replacement support for faster development. Neat.
[**hybridsjs/hybrids**
*👾 Web Components from plain objects and pure functions! — hybridsjs/hybrids*github.com](https://github.com/hybridsjs/hybrids)

## 7. Sigil

[Sigil](https://github.com/sigiljs/sigil) is a “functional web component library”. It features reusable html elements using web components, a virtual dom for super fast re-rendering using [snabbadom](https://github.com/snabbdom/snabbdom), html templating language that allows bindings to attributes & properties with powerful expressions, pure functional view component style to reduce re-renderings,support for immutable flux based stores like [Redux](http://redux.js.org/) and [Kamea](https://github.com/sigiljs/kamea) and more. Try it out for yourself with [JSFiddle here](https://jsfiddle.net/8hoddkb2/1/).