Production
View SourceIntroduction
You build and run a Phoenix app with Corex in production locally. Corex ships as plain HEEx plus ESM JavaScript; mix assets.deploy minifies and digests the same CSS and per-hook chunks you use in development.
Before you start
| Requirement | Notes |
|---|---|
SECRET_KEY_BASE | mix phx.gen.secret |
| Database URL | Production or local stand-in |
| ESM Esbuild | --format=esm --splitting from Manual installation |
How it works
MIX_ENV=prod mix compilebuilds the release artifacts.mix assets.deployruns Tailwind and Esbuild with--minify, then digests files underpriv/static.- With splitting enabled, you get an entry chunk plus one chunk per lazy hook under
priv/static/assets/js/.
Steps
Generate a secret:
mix phx.gen.secret
Set environment variables (example .env, add to .gitignore):
export SECRET_KEY_BASE="__YOUR_SECRET__"
export DATABASE_URL="ecto://postgres:postgres@localhost/my_app_dev"
source .env
MIX_ENV=prod mix compile
MIX_ENV=prod mix assets.deploy
MIX_ENV=prod mix phx.server
Visit http://localhost:4000/.
Related
- Manual installation — Esbuild ESM setup
- Design — CSS you import is the same in prod