7

そこで、Elm と WebRTC を一緒に試しています。ただし、WebRTC の場合、javascript との相互運用が必要です。そこで、WebRTC と main.js の両方に必要なスクリプト インクルードを含む index.html を作成しました。

ただし、elm-reactor を使用しています。これはとてもいいです。しかし、main.js はありません。elm-make で作成できますが、手動で更新する必要があります。

では、elm-reactor を埋め込まれた elm と一緒に動作させる方法はありますか?

注:執筆時点で最新のElm 0.18を使用しています。

4

3 に答える 3

4

今日 ( ) の時点で、アプリケーションをカスタム HTML に埋め込むためにelm-reactor0.18.0を公式に使用することはできません。また、追加のセットアップなしでelm-reactorでポート サブスクリプションを持つこともできません。

Create Elm Appまたは代替手段のようなものを使用することを検討してください。

于 2016-12-26T16:44:31.437 に答える
1

少しハックする気があれば、独自の index.html を 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>

ポートまたはフラグを使用する場合は、次の例Elm.App.fullscreen(flags)を使用します (ポートを使用するには etcが必要ですが、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>
于 2016-12-28T17:23:11.827 に答える