1m read
Tags: elixir, phoenix, template

Recently, I started working on a few projects that required me to create a phoenix project with liveview and tailwindcss; reusing some of the code currently powering this blog content with markdown.

Now I could create a base project and then copy the code over, but I wanted to automate this process. I also wanted to make it easy for others to use this template.

I decided to try using mix template and mix generator by the amazing PragDave to create my reusable phoenix project template.

Mix Template and Mix Generator

Mix Template is a mix task that allows you to install and manage mix templates; and Mix Generator is a mix task that can be used to create new projects from said templates.

Both tools are fairly simple to use and can be installed using the following command:

$ mix archive.install hex mix_templates
$ mix archive.install hex mix_generator

Once installed, they can be used to create a new project from a template or to create a new template. We can validate the tools installed correctly by running the following commands:

mix template.hex

Which should return a list of available templates, like:

Templates on hex.pm

gen_template_project:
    A replacement for `mix new «project»` that generates files which
    I believe to be easier to read and maintain.

gen_template_ecto_service:
    A template `mix gen ecto_service «project»` that generates
    a project for building stand alone ecto services (using Posgres)

gen_template_umbrella:
    Generate a basic umbrella project.

What do you think of what I said?

Share with me your thoughts. You can tweet me at @allanmacgregor.