mirror of
https://codeberg.org/setop/elm-scripting
synced 2025-11-08 21:49:57 +00:00
feat: auto discover main module
This commit is contained in:
@@ -14,24 +14,24 @@ Next, we concatenate this with the Elm JavaScript output and an app launcher sni
|
|||||||
|
|
||||||
* No event loop
|
* No event loop
|
||||||
* Hence, no [TEA](https://guide.elm-lang.org/architecture/); the `main` function must return a static view
|
* Hence, no [TEA](https://guide.elm-lang.org/architecture/); the `main` function must return a static view
|
||||||
* The Elm app module must be called "Main"
|
* ~~The Elm app module must be called "Main"~~
|
||||||
* Nodes can only have one parent (this should always be the case)
|
* Nodes can only have one parent (this should always be the case)
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
1. Clone this repository and navigate into your local copy
|
1. Clone this repository and navigate into your local copy
|
||||||
2. Run `elm init`.
|
2. Run `elm init`.
|
||||||
3. Create `src/Main.elm` with the following content:
|
3. Create `src/Hello.elm` with the following content:
|
||||||
|
|
||||||
```elm
|
```elm
|
||||||
module Main exposing(main)
|
module Hello exposing(main)
|
||||||
|
|
||||||
import Html exposing (p, text)
|
import Html exposing (p, text)
|
||||||
|
|
||||||
main = p [] [text "Hello World!"]
|
main = p [] [text "Hello World!"]
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Run `./build.sh`; this generates the corresponding HTML code:
|
4. Run `./build.sh src/Hello.elm`; this generates the corresponding HTML code:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
2
build.sh
2
build.sh
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
w1="$(mktemp out_$$_1_XXXX.js)"
|
w1="$(mktemp out_$$_1_XXXX.js)"
|
||||||
|
|
||||||
elm make --optimize --output=${w1} src/Main.elm 1>&2
|
elm make --optimize --output=${w1} $1 1>&2
|
||||||
|
|
||||||
w2="$(mktemp out_$$_XXXX.js)"
|
w2="$(mktemp out_$$_XXXX.js)"
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// and the Elm app code
|
// and the Elm app code
|
||||||
|
|
||||||
// here we lanch the app
|
// here we lanch the app
|
||||||
var app = Elm.Main.init({ node: document.getElementById("elm") });
|
Elm[Object.keys(Elm)[0]].init({ node: document.getElementById("elm") });
|
||||||
|
|
||||||
document.children[0].dump();
|
document.children[0].dump();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user