This is a small bootstrap / starter pack for building mobile apps using Elm and Capacitor.
- Requirements
- Setup
- Development - Elm
- Development - JS, CSS, etc.
- Build
- Some Internal Details
You'll need these:
- Node (any latest) and
yarn
. - Android Studio and Android SDK.
- After installing Android Studio and Android SDK, add a system image that has a
Target
ofAndroid 11.0
(as Capacitor seems to work with that version well).
- Clone this repo locally.
- Then run
yarn install
in the folder. - Run a
yarn build
to compile the project once.
If you have Android Studio and Android SDK and a device setup, you can now view / run the project in an emulator by:
- running
yarn cap open android
, - and then running the project in Android Studio.
- All Elm source files are in
src/*.elm
. - When you make changes and want to test them, just run
yarn build
oryarn dev-build
(debug mode).
- All custom JS is in
public/js/index.js
. - You can add more JS files there.
- All Capacitor-related code would ideally go here.
- Remember to include those files in your
public/index.html
via<script>
tags. - If you use
import
statements, make sure you addtype="module"
. Eg.<script src="./js/custom.js" type="module"></script>
.
- Add all custom CSS files in
public/css
. - The project uses Tailwind so you can also use Tailwind classes anywhere in your
Elm
files and inpublic/index.html
along with using them via@apply
inindex.css
and elsewhere.
Anytime you make changes to JS, CSS, HTML or Elm files, make sure to run yarn build
or yarn dev-build
. There is no HMR. You can setup a custom nodemon
/ watcher to have a pseudo-HMR experience.
- If you want to build the project for production:
> yarn build
- If you'd like Elm's
Debug
to be allowed:
> yarn dev-build
How stuff works:
- The project files are spread across these folders/files:
public
├── css
│ ├── index.css <-- custom CSS goes here. You can also add more CSS files.
├── index.html <-- the main entry-point for the project.
└── js
└── index.js <-- all custom JS goes here. You can also add more JS files but just make sure to include them in `index.html`
src
└── Main.elm <-- all Elm code goes here. You can add more Elm files inside `src` folder.
-
The build (dev or prod) basically has to take care of building Elm files into a
js
file, then compiling all CSS data into a single file, and finally adding them to the project. -
The moment you run
yarn dev-build
oryarn build
, you'll notice that two new files get added into thepublic
directory:
public
├── css
│ ├── index.css
│ └── style.css <-- auto-generated
├── index.html
└── js
├── elm.js <-- auto-generated
└── index.js
-
A modern browser can run/serve
index.html
as-is but since we're building this for a mobile WebView (Capacitor runs through that), we need to "transpile" the JS. -
Which is why this project uses
parcel
. One of the commands inyarn build
bundles the project viaparcel build
and outputs the compiled project in aweb
folder. -
Then,
yarn cap sync
(part ofyarn build
) simply updates the project (Android/iOS) by copying over the contents of theweb
into the Android/iOS project.