wking-io / elm-live

⚡ A flexible dev server for Elm. Live reload included.
https://elm-live.com
MIT License
1.05k stars 61 forks source link

how to pass elm flags #275

Open johndeighan opened 2 weeks ago

johndeighan commented 2 weeks ago

I love the fact that I can just globally install elm and elm-live, do an "elm init", create a src/Main.elm file and invoke elm-live. Short and simple. But to make my app responsive, I need to 1) respond to "window resized" events and 2) initially, get the window size. From research, I see that to get the initial window size, I need to pass in elm flags in the index.html file:

<script>
let app = Elm.Main.init({
flags: {
windowHeight: window.innerHeight,
windowWidth: window.innerWidth
}
})
</script>

Well, darn... I didn't want to have to mess with index.html - elm-live creates that automatically for me.

I tried to edit the index.html file created, but unfortunately, elm-live rebuilds it each time it's run. Is there some way to handle this without having to change my development process?

tom-a-horrocks commented 1 week ago

Try running elm-live src/Main.elm --open -- --output=app.js. This way, elm-live will compile app.js and use index.html as-is. A few gotchyas if you're on Windows: