Skip to content

Instantly share code, notes, and snippets.

@danneu
Last active May 9, 2022 06:17
Show Gist options
  • Save danneu/77d9000d390098064cc30f66353a5562 to your computer and use it in GitHub Desktop.
Save danneu/77d9000d390098064cc30f66353a5562 to your computer and use it in GitHub Desktop.

Revisions

  1. danneu revised this gist May 9, 2022. No changes.
  2. danneu revised this gist May 9, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -79,3 +79,5 @@ parcel build index.html
    # Creates ./dist folder with html, js, css files
    ```

    Parcel docs: https://parceljs.org/getting-started/webapp/

  3. danneu revised this gist May 9, 2022. 2 changed files with 56 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion 0-README.md
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ Project structure so far:
    └── Main.elm
    ```

    Save Elm boilerplate to `src/Main.elm`: https://ellie-app.com/hphB4mjXYBpa1
    Save Elm boilerplate to `src/Main.elm`: (See attached `1-Main.elm` file)

    Save this to index.html:

    55 changes: 55 additions & 0 deletions 1-Main.elm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    module Main exposing (main)

    import Browser
    import Html exposing (..)
    import Html.Attributes exposing (..)
    import Html.Events exposing (..)


    type alias Model =
    { draft : String
    }


    type alias Flags =
    { initDraft : String }


    init : Flags -> ( Model, Cmd Msg )
    init flags =
    ( { draft = flags.initDraft
    }
    , Cmd.none
    )


    type Msg
    = DraftChanged String


    update : Msg -> Model -> ( Model, Cmd Msg )
    update msg model =
    case msg of
    DraftChanged value ->
    ( { model | draft = value }
    , Cmd.none
    )


    view : Model -> Html Msg
    view model =
    div []
    [ textarea
    [ onInput DraftChanged ]
    [ text model.draft ]
    ]


    main : Program Flags Model Msg
    main =
    Browser.element
    { init = init
    , view = view
    , update = update
    , subscriptions = \_ -> Sub.none
    }
  4. danneu revised this gist May 9, 2022. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -72,3 +72,10 @@ parcel index.html

    (Or use `npx parcel index.html` if you installed parcel locally with `npm install --save-dev parcel`. `npx` uses the parcel binary found in your project's `./node_modules/.bin` since it otherwise isn't in your $PATH.)

    When you're ready for a production build:

    ```shell
    parcel build index.html
    # Creates ./dist folder with html, js, css files
    ```

  5. danneu revised this gist May 9, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,21 @@
    # Elm quickstart with Parcel

    Create project boilerplate:

    ```shell
    mkdir my-elm-project
    cd my-elm-project
    elm init
    touch src/Main.elm # This is where we put our Elm app

    echo '{}' > package.json # Empty package.json to install NPM libs

    npm install -g parcel # Or install project-locally with `npm install --save-dev parcel`

    touch example.scss # Just to show that Parcel automatically handles things like .scss
    touch index.html
    touch index.js

    npm install uuid # Let's use an NPM library for demonstration
    ```

  6. danneu revised this gist May 9, 2022. 1 changed file with 36 additions and 11 deletions.
    47 changes: 36 additions & 11 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -4,32 +4,59 @@
    mkdir my-elm-project
    cd my-elm-project
    elm init
    touch src/Main.elm # This is where we put our Elm app
    echo '{}' > package.json # Empty package.json to install NPM libs
    npm install -g parcel # Or install project-locally with `npm install --save-dev parcel`
    touch example.scss # Just to show that Parcel automatically handles things like .scss
    touch index.html
    touch index.js
    npm install uuid # Let's use an NPM library for demonstration
    ```

    Project structure so far:

    ```
    .
    ├── elm.json
    ├── example.scss
    ├── index.html
    ├── index.js
    ├── package.json
    └── src
    └── Main.elm
    ```

    Save Elm boilerplate to `src/Main.elm`: https://ellie-app.com/hphB4mjXYBpa1

    Save this to index.html:

    ```html
    <!doctype html>
    <!DOCTYPE html>
    <head>
    <link rel="stylesheet" href="./example.scss" />
    <script src="./src/Main.elm"></script>
    <link rel="stylesheet" href="./example.scss" />
    </head>
    <body>
    <main/>
    <script>
    const app = Elm.Main.init({
    node: document.querySelector('main')
    })
    </script>
    <main></main>
    <script type="module" src="index.js"></script>
    </body>
    ```

    Inside `index.js` we mount our Elm app to `<main>` and can import NPM libraries and use them:

    ```javascript
    // index.js
    import { Elm } from './src/Main.elm'
    import * as uuid from 'uuid'

    const app = Elm.Main.init({
    node: document.querySelector('main'),
    flags: {
    // Example of using npm library to pass value into Elm via flag
    initDraft: uuid.v4()
    }
    })
    ```

    Use `parcel` to run dev server:

    ```shell
    @@ -39,5 +66,3 @@ parcel index.html

    (Or use `npx parcel index.html` if you installed parcel locally with `npm install --save-dev parcel`. `npx` uses the parcel binary found in your project's `./node_modules/.bin` since it otherwise isn't in your $PATH.)

    Read more about parcel: https://parceljs.org/getting-started/webapp/

  7. danneu revised this gist May 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 0-README.md
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ parcel index.html
    # Navigate browser to http://localhost:1234
    ```

    (Or use `npx parcel index.html` if you installed parcel locally with `npm install --save-dev parcel`. `npx` uses the parcel binary found in your project's `./node_modules/.bin`)
    (Or use `npx parcel index.html` if you installed parcel locally with `npm install --save-dev parcel`. `npx` uses the parcel binary found in your project's `./node_modules/.bin` since it otherwise isn't in your $PATH.)

    Read more about parcel: https://parceljs.org/getting-started/webapp/

  8. danneu revised this gist May 9, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion 0-README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ mkdir my-elm-project
    cd my-elm-project
    elm init
    echo '{}' > package.json # Empty package.json to install NPM libs
    npm install -g parcel
    npm install -g parcel # Or install project-locally with `npm install --save-dev parcel`
    touch example.scss # Just to show that Parcel automatically handles things like .scss
    touch index.html
    ```
    @@ -37,5 +37,7 @@ parcel index.html
    # Navigate browser to http://localhost:1234
    ```

    (Or use `npx parcel index.html` if you installed parcel locally with `npm install --save-dev parcel`. `npx` uses the parcel binary found in your project's `./node_modules/.bin`)

    Read more about parcel: https://parceljs.org/getting-started/webapp/

  9. danneu revised this gist May 9, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion 0-README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ mkdir my-elm-project
    cd my-elm-project
    elm init
    echo '{}' > package.json # Empty package.json to install NPM libs
    npm install -g parcel # OR npm install --save-dev parcel
    npm install -g parcel
    touch example.scss # Just to show that Parcel automatically handles things like .scss
    touch index.html
    ```
    @@ -37,3 +37,5 @@ parcel index.html
    # Navigate browser to http://localhost:1234
    ```

    Read more about parcel: https://parceljs.org/getting-started/webapp/

  10. danneu revised this gist May 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 0-README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ mkdir my-elm-project
    cd my-elm-project
    elm init
    echo '{}' > package.json # Empty package.json to install NPM libs
    npm install -g parcel
    npm install -g parcel # OR npm install --save-dev parcel
    touch example.scss # Just to show that Parcel automatically handles things like .scss
    touch index.html
    ```
  11. danneu revised this gist May 9, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@
    mkdir my-elm-project
    cd my-elm-project
    elm init
    echo '{}' > package.json
    echo '{}' > package.json # Empty package.json to install NPM libs
    npm install -g parcel
    touch example.css
    touch example.scss # Just to show that Parcel automatically handles things like .scss
    touch index.html
    ```

    @@ -17,7 +17,7 @@ Save this to index.html:
    ```html
    <!doctype html>
    <head>
    <link rel="stylesheet" href="./example.css" />
    <link rel="stylesheet" href="./example.scss" />
    <script src="./src/Main.elm"></script>
    </head>
    <body>
  12. danneu revised this gist May 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 0-README.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Save this to index.html:
    <!doctype html>
    <head>
    <link rel="stylesheet" href="./example.css" />
    <script src="./src/Main.elm" />
    <script src="./src/Main.elm"></script>
    </head>
    <body>
    <main/>
  13. danneu revised this gist May 9, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Elm quickstart with Parcel

    ```shell
    mkdir my-elm-project
    cd my-elm-project
  14. danneu created this gist May 9, 2022.
    37 changes: 37 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    ```shell
    mkdir my-elm-project
    cd my-elm-project
    elm init
    echo '{}' > package.json
    npm install -g parcel
    touch example.css
    touch index.html
    ```

    Save Elm boilerplate to `src/Main.elm`: https://ellie-app.com/hphB4mjXYBpa1

    Save this to index.html:

    ```html
    <!doctype html>
    <head>
    <link rel="stylesheet" href="./example.css" />
    <script src="./src/Main.elm" />
    </head>
    <body>
    <main/>
    <script>
    const app = Elm.Main.init({
    node: document.querySelector('main')
    })
    </script>
    </body>
    ```

    Use `parcel` to run dev server:

    ```shell
    parcel index.html
    # Navigate browser to http://localhost:1234
    ```