-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
35 lines (28 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
// Require index.html so it gets copied to dist (for local dev only)
require('./index.html');
let Elm = require('./elm-src/Main.elm');
let mountNode = document.createElement("DIV");
mountNode.id = "app";
document.body.appendChild(mountNode);
let app = Elm.Main.embed(mountNode, {env: process.env.NODE_ENV});
function appendScript(src) {
let link = document.createElement('script');
link.setAttribute('type', 'module');
link.setAttribute('src', src);
document.head.appendChild(link);
}
// subscription to the load out port from elm
app.ports.loadWebComponent.subscribe(function (componentToLoad) {
switch (componentToLoad) {
case "vanilla-hello-world":
appendScript("components/vanilla/dist/hello-world.js");
break;
case "react-hello-world":
appendScript("components/react/dist/hello-world.js");
break;
case "vue-hello-world":
appendScript("components/vue/dist/vue-hello-world.js");
break;
}
});