Bootstrapping an Elm Project
I'm a web-focused developer with a passion for exploring new ideas and hopefully sharing more of them through this blog ๐
Search for a command to run...
I'm a web-focused developer with a passion for exploring new ideas and hopefully sharing more of them through this blog ๐
No comments yet. Be the first to comment.
When to use for, map, doseq, and run!

Property based testing leading to unexpected URL discoveries

Some Takeaways from AI-assisted Rescript Exploration

Do you believe your job can be done by AI? Up until very recently I believed this was all hype. No way this could happen. There have always been proclamations of new technologies like AI taking jobs. Most of the time dismissed as fantasy, most takes ...

Return the most frequently used terminal commands

Elm is a delightful language for building reliable web applications. It's a language that gets compiled to JavaScript and so is used to build applications that run in a web browser.
In this post, we're going to explore different ways of starting an Elm project, starting with the simplest and moving on to setups with more advanced features such as hot-reload in development.
Let's get started!
Before we get started, please make sure to Install Elm
To confirm if you have Elm installed, you can try running the interactive repl using the elm repl command. If you get a prompt such as the one shown in this image, you're good to go ๐

This is the officially supported way of creating a new Elm project.
mkdir my-awesome-elm-project
cd my-awesome-elm-project
elm init inside this directory and you should get a prompt like the one below:
Enter key and it should create an elm.json file in the current directory. A src directory will also be created.It is a good idea to read through the linked resource that talks more about starting new Elm projects
Main.elm file in the src directory. Once we've created the file, let's add some Elm code that should show us the classic "Hello World!" message once we run it.module Main exposing (main)
import Browser
import Html exposing (h1, text)
main =
h1 [] [ text "Hello World!" ]
To run the code, let's run elm reactor in our directory and it should start a new local server at http://localhost:8000. elm reactor is the simplest way to get started running Elm code.
Once you navigate to http://localhost:8000, you should see an interface like the following.

Click on the src link, then Main.elm and you should be greeted by our "Hello World!" message.
And that's it! We've successfully created a project the elm init command and run it using elm reactor.
elm itselfThis is an extension of elm reactor and includes the ability to compile our Elm code to static HTML.
Using the same project from our previous section, we can compile the project using the command:
elm make src/Main.elm
Once we run this command, an index.html file will be generated in the current working directory, and if you open it in a web browser, you should see the same "Hello World" message.
I don't have lots of experience with elm make so that's as far as I'll go with it.
Parcel is a "Blazing fast, zero configuration web application bundler" and is my personal favourite to get started with an Elm application quickly. It handles compiling your Elm code to JavaScript and is super easy to get started with.
You can create an Elm application compiled by Parcel in a few simple steps:
yarn global add parcel-bundler or npm install -g parcel-bundler
Follow the instructions in the Elm section of the Parcel website, which involves:
creating an index.html file with the following contents:
<html>
<body>
<main></main>
<script src="./index.js"></script>
</body>
</html>
index.js file with the following contents:import { Elm } from "./Main.elm"
Elm.Main.init({
node: document.querySelector("main"),
})
Main.elm file with the following contents:module Main exposing (main)
import Browser
import Html exposing (h1, text)
main =
h1 [] [ text "Hello, from Parcel!" ]
parcel index.html
I love this setup so much that I've created my own starter project based on Parcel. Feel free to check it out on GitHub
๐คทโโ๏ธ
This is not meant to be a comprehensive list, and any suggestions/additions are welcome in the comments section below.
I hope these options are useful for you when starting out your next Elm project ๐