Packages

A post-installation tool that converts a default Phoenix installation to use LiveView-only with inline HEEx templates, removing controller-based infrastructure.

Current section

Files

Jump to
phoenix_min lib phoenix_min.ex
Raw

lib/phoenix_min.ex

defmodule PhoenixMin do
@moduledoc """
Phoenix Min - Slim down Phoenix to LiveView-only with inline HEEx templates.
Phoenix Min is a post-installation tool that transforms a default Phoenix
installation by:
- Removing controller-based infrastructure (PageController, PageHTML, etc.)
- Converting all generated templates to inline HEEx using the `~H` sigil
- Creating a LiveView-based home page
- Converting layouts to inline templates
- Converting error views to inline templates
- Updating tests to work with LiveView
- Cleaning up template directories
## Installation
Add to your Phoenix project's `mix.exs`:
{:phoenix_min, "~> 0.1.0", only: [:dev], runtime: false}
Then run:
mix igniter.install phoenix_min
Or simply:
mix phoenix_min.install
## What Gets Modified
- `lib/your_app_web/router.ex` - Root route changed to LiveView
- `lib/your_app_web/home_live.ex` - New LiveView with inline template (created)
- `lib/your_app_web/components/layouts.ex` - Converted to inline templates
- `lib/your_app_web/controllers/error_html.ex` - Converted to inline templates
- `lib/your_app_web/controllers/page_*` - Removed
- `lib/your_app_web/components/layouts/*` - Removed
- `lib/your_app_web/controllers/error_html/*` - Removed
- `test/your_app_web/controllers/page_controller_test.exs` - Converted to LiveView test
## Philosophy
Phoenix Min embraces:
1. **LiveView-first**: All pages are LiveViews, no controllers
2. **Colocation**: Templates live in the same file as behavior
3. **Simplicity**: Less files, less directories, easier navigation
4. **Flexibility**: Works with or without Ecto, assets, gettext, etc.
"""
@doc """
Returns the web module name for a given app name.
## Examples
iex> PhoenixMin.web_module(:hello)
HelloWeb
iex> PhoenixMin.web_module(:my_app)
MyAppWeb
"""
def web_module(app_name) when is_atom(app_name) do
base =
app_name
|> Atom.to_string()
|> Macro.camelize()
Module.concat([base <> "Web"])
end
end