我正在尝试将端口与 elm-app 一起使用。以前我使用elm-live
香草设置,并且能够插入这样的端口:
索引.html
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script>
window.addEventListener("load", function(event) {
var app = Elm.Main.fullscreen(localStorage.session || null);
app.ports.storeSession.subscribe(function(session) {
localStorage.session = session;
});
...
这行得通,elm-live 似乎嵌入elm.js
在<head>
index.html 中。
但是,当我尝试将此设置用于带有 的端口时create-elm-app
,已编译的 javascript 嵌入在 的底部<body>
,因此像我所做的那样添加会<script>
导致:
(index):68 Uncaught ReferenceError: Elm is not defined
at (index):68
嵌入 JS 端口的最佳方式是什么?