Production
View SourceIntroduction
You build and run a Phoenix app with Corex in production. 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 |
| Design (if used) | corex.design.build runs before Tailwind/Esbuild in assets.deploy. Keep {:corex_design, ..., runtime: false} (no only: :dev) so the Mix task is available under MIX_ENV=prod. That flag does not rebuild CSS at request time. |
| MCP | Mount only in :dev / :test; never enable in :prod |
How it works
MIX_ENV=prod mix compilebuilds the app.mix assets.deployshould runmix corex.design.build(when you use Design), then Tailwind and Esbuild with--minify, then digest files underpriv/static.- With ESM splitting, 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/.
For a release, run the same asset pipeline in your release build (Docker/mix release) so priv/static includes digested CSS and JS. Keep plug Corex.MCP out of the production endpoint.
--a11y plugs call Corex.Design.Accessibility (cookie → data-*); they do not generate CSS. Mix.Release omits runtime: false apps unless listed, so add corex_design: :load to the release applications list. See Accessibility.
Related
- Manual installation — Esbuild ESM and Design aliases
- Design — CSS you import is the same in prod
- Accessibility —
corex_design: :loadwhen usingmix releasewith--a11y - MCP — never enable in
:prod