使用elm-reactor和Elm嵌入HTML?

所以我一起尝试Elm和WebRTC.但是对于WebRTC,我需要一些互操作到 javascript.所以我为WebRTC和main.js创建了一个带有所需脚本包含的index.html.

但是,我正在使用榆树反应堆.哪个超级好看.但是没有main.js.我可以用elm-make创建它,但是我必须手动更新它.

那么,有没有办法让榆树反应堆与嵌入式榆树一起工作?

注意:我正在使用Elm 0.18,最新的写作.

如果你愿意破解,那么完全可能是 use your own index.html with elm reactor.只需将以下内容放在index.html文件中并在reactor中打开它(例如 http://localhost:8000/src/index.html):
<html>

<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="styles.css"><!-- Put your styles in folder with index.html -->
</head>

<body>
  <div style="width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #9A9A9A; font-family: &#39;Source Sans Pro&#39;;">
    <div style="font-size: 3em;">Building your project!</div>
    <img src="/_reactor/waiting.gif">
    <div style="font-size: 1em">With new projects,I need a bunch of extra time to download packages.</div>
  </div>
</body>

<!-- Fonts and external JS and styles are available,I've put Ace for example -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.4/ace.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.4/theme-chrome.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.4/worker-lua.js"></script>

<!-- Put the name of your app here (my sources place in `src` forder) -->
<script type="text/javascript" src="/_compile/src/YourApp.elm"></script>

<!-- Removes splash and starts elm app. -->
<script type="text/javascript">
while (document.body.firstChild) {
  document.body.removeChild(document.body.firstChild);
}
runElmProgram();
</script>

</html>

如果要使用端口或标志,请使用the following example(需要Elm.App.fullscreen(flags)等来使用端口,但使用runElmProgram()来显示错误):

<!doctype html>
<meta charset=utf-8>
<title>a title</title>
<link href=/bundle.css rel=stylesheet>
<body></body>
<script src="/_compile/Main.elm"></script> <!-- this will fail in production -->
<script src="/elm-bundle.js"></script> <!-- this will fail in development -->
<script>
var app
var flags = {}

try {
  app = Elm.App.fullscreen(flags)

  /* app.ports is now available */
} catch (e) {
  // this will run in case there are compile errors:
  var stylesheets = document.querySelectorAll('link')
  for (var i = 0; i < stylesheets.length; i++) {
    stylesheets[i].parentNode.removeChild(stylesheets[i])
  }
  runElmProgram()
}
</script>

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...