- This feature branch reintroduces JS modules for any elm application or package
- I pulled the npm package and binaries because I jumped the gun on the actual 0.19.1 elm release
- To build manually install stack: https://docs.haskellstack.org/en/stable/README/#how-to-install then:
git clone ..
stack build
# The binary is then in:
echo $(stack path --local-install-root)/bin/elm[.exe]
elm init
- Create a Javascript module,
src/Elm/Kernel/JS.js
- Important notes:
- Javascript modules must be in a
Elm/Kernel/
folder
- Javascript modules must be in a
// Nothing crazy here, the JS.log function logs the string and returns it
function _JS_log(s) {
console.log(s);
return s;
}
- Create an Elm module to call our javascript,
src/Main.elm
module Main exposing(..)
import Html exposing (..)
import Elm.Kernel.JS
log : String -> String
log = Elm.Kernel.JS.log
main = text <| log <| "HelloWorld"
- Compile
elm make src/Main.elm
- Open
index.html
- "HelloWorld" should be printed to the console and on the page
- More js module examples are here elm/core library.