This is an example that uses:
- elm-watch for Elm compilation
- esbuild for TypeScript compilation
- SWC for minification (
postprocess.js
) - A little Node.js dev server for routing and proxying, with no dependencies (
dev-server.js
) - run-pty to run the above with just one command
- elm-tooling to install Elm and elm-format
See example.yml for an example GitHub Actions workflow.
See also the minimal elm-watch example.
Don’t be intimidated by the number of steps! They include building elm-watch itself, as well as making a production build, and cloning demo submodules. Your own project would have fewer steps.
cd
to the repository root (not this folder). We need to start there because this example uses a locally built elm-watch instead of a pre-built elm-watch from npm.- Run
npm ci
to install dependencies for building elm-watch. - Run
npm run build
to build elm-watch. - Run
cd example
to go into this folder. - Run
git submodule update --init
to fetch some real-world Elm apps for demoing. - Run
npm ci
to install dependencies for this example. - Run
npm start
to start elm-watch, esbuild and the Node.js dev server for development, using run-pty. Alternatively, runnpm run start-advanced
for some extra run-pty goodness (seerun-pty.json
if you’re interested). - Visit some Elm app in the browser (see below): Go to http://localhost:8000 (the dev server, recommended), or http://localhost:9000 (raw esbuild server).
- Edit an Elm file in
src/
orpublic/submodules/
and watch the browser be automatically updated. - Stop elm-watch, esbuild and the dev server.
- Run
npm run build
to build for production, using elm-watch, esbuild and SWC. - Run
npm run try-production
to to try out the production build. It uses esbuild only for serving static files, and the Node.js dev server for proxying. It’s the same URLs as before: http://localhost:8000 and http://localhost:9000. (Note: This command is for trying out the production build locally, not something you’d actually run in production to serve the files.)
This example has many Elm apps (many targets in elm-watch.json
):
- Some simpler demo/test apps in
src/
just need an HTML file served to work. Visit http://localhost:9000 – which is just esbuild’s static file server – to get links to them. These are useful when developing elm-watch itself but pretty boring as a demo. - There are also some real world apps in
public/submodules/
. They useBrowser.application
, so they need a proper server to work fully – that’s wheredev-server.js
comes into play. Visit http://localhost:8000 to get links to them. These are much more fun demo material.