Phoenix Elixir Tailwind Alpine Liveview
Install Elixir using package-manager yay -S elixir
a. Check: elixir -v
Setup hex archive manager mix local.hex && mix local.rebar
a. Check: mix hex
Install Phoenix mix archive.install hex phx_new
Create new project mix phx.new <project_name>
Setup tailwind
$ cd assets && npm init -y
assets $ npm i -D tailwindcss autoprefixer postcss postcss-import
assets $ npx tailwindcss init -p
postcss-import: {}
to postcss.config.js at the topmode: 'jit'
and content: ["../lib/*_web/**.*ex", "./js/**/*.js"]
to tailwindcss.config.jsnpx: [
"tailwindcss",
"-i=css/app.css",
"-o=../priv/static/assets/app.css"
"--postcss",
"--watch",
cd: Path.expand("../assets", __DIR__)
]
Setup alpine
assets $ npm i alpinejs
import Alpine from "alpinejs";
window.Alpine = Alpine;
Alpine.start();
In mix.exs aliases
"cmd --cd assets npm install"
to setup
tail"cmd --cd assets npm run deploy"
to assets.deploy
headIn assets/package.json, add script: "deploy": "NODE_ENV=production tailwindcss --postcss --minify -i css/app.css -o ../priv/static/assets/app.css"
Phoenix is a web development framework written in Elixir which implements the server-side Model View Controller (MVC) pattern.
Base setup includes:
mix help --search "phx"
Regarding Ecto:
# config/config.exs
config :test,
ecto_repos: [Test.Repo]
config :test, Test.Repo,
database: Path.expand("../test_dev.db", Path.dirname(__ENV__.file)),
# test/repo.ex
defmodule Test.Repo do
use Ecto.Repo,
otp_app: :test,
adapter: Ecto.Adapters.SQLite3
end
Schema is what maps data from db to elixir format, and contains changesets.
Migrations are used to create/alter tables such that they approach the state specified by schemas.
Regarding Assets:
Phoenix uses esbuild to pack css and js from assets/
dir and served from priv/static
dir. Static assets are not copied over automatically!
Regarding Templates:
Be careful with variables in rendered html. If rendering from inside functions, make sure to use @variable
instead of assign.variable