elm-app-webcomponent

1.0.0 • Public • Published

Build web-component using create-elm-app

Installation

  1. add this plugin as a development dependency of a project you created with create-elm-app
yarn add -D elm-app-webcomponent
  1. use plugin in elmapp.config.js
exports.configureWebpack = require('elm-app-webcomponent');

Usage

  1. You need to create an entry point for your web component in src/custom-element.js, this is a boilerplate you might want to start with:
const Elm = require('./Main');
const css = require('./main.css').toString();

customElements.define('my-webcomponent',
    class extends HTMLElement {

        constructor() {
            super();

            const appRoot = document.createElement('div');
            const appStyles = document.createElement('style');
            appStyles.textContent = css;

            const shadowRoot = this.attachShadow({mode: 'open'});
            shadowRoot.appendChild(appStyles);
            shadowRoot.appendChild(appRoot);
            this.appRoot = appRoot;
        }

        connectedCallback() {
            const app = Elm.Elm.Main.init({ node: this.appRoot });
            this.app = app;
        }
});
  1. Run elm-app build as usual to build your web component.

Readme

Keywords

none

Package Sidebar

Install

npm i elm-app-webcomponent

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

2.67 kB

Total Files

3

Last publish

Collaborators

  • anatoliy