How to Easily Setup Mithril.js Project
January 03, 2020
The Mithril project provides great documentation. You should make sure to check it out. You’ll probably notice that there is no mention of a starter template to rapidly start a project. It recommends starting by importing Mithril.js from CDN. While that’s an OK solution for working through a tutorial, it’s not something we need to launch a new full-fledged project with Mithril.js.
If you ever used React, then you probably heard of create-react-app, a great tool that enables us to create React apps with no build configuration. Luckily, there is a similar tool for Mithril, called create-mithril-app, and like CRA, it is easy to use.
I will assume that you have newer versions of Node.js and npm installed on your machine.
npx create-mithril-app my-new-appcd my-new-appnpm inpm run dev
Note: I’m using
npx command to ensure I’m getting the latest version of create-mithril-app and to avoid installing the tool globally. If you want to learn more about npx, check out this great article by Kat Marchán.
This will create a new project in my-new-app folder, install all the necessary dependencies, and start webpack-dev-server. If you open the browser to http://localhost:8020, you should see a
Hello World screen.
Great, you have a new Mithril.js project set up, now go build something great!