dwyl / learn-elm

:rainbow: discover the beautiful programming language that makes front-end web apps a joy to build and maintain!
https://github.com/dwyl/learn-elm
477 stars 42 forks source link

using elm-live with SPA #156

Open SimonLab opened 4 years ago

SimonLab commented 4 years ago

elm-live can be used to compile a Elm single page application. You can install elm-live with npm: npm install -g elm-live and then you'll be able to run the following command:

elm-live src/Main.elm --pushstate -- --output elm.js

the command above will compile the src/Main.elm file. The documentation (elm-live --help) for the flag--pushstate` is:

Forces the index.html or whatever filename you have passed to the --start-page flag to always be served. Must be used when building with Browser.application. (default: false)

This means that any endpoint of the application will use the same start origin instead of looking for a specific file.

Then all the flags defined after -- are sent directly to elm make instead of elm-live. In our case the Elm application will be compiled to the output file elm.js. By default elm-live compile the application to index.html which means that if you have already an index file it will be overridden.