Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to pass elm flags #275

Open
johndeighan opened this issue Sep 8, 2024 · 1 comment
Open

how to pass elm flags #275

johndeighan opened this issue Sep 8, 2024 · 1 comment

Comments

@johndeighan
Copy link

johndeighan commented Sep 8, 2024

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
Copy link

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:

  • If you launch elm-live from PowerShell, you'll need to include -- in quotes: elm-live src/Main.elm --open "--" --output=app.js
  • Slightly unrelated, but if you're using VSCode then compiling your app to "elm.js" causes weird errors! Use "app.js" or "main.js" instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants