mix phx.new (Phoenix v1.8.1)
View SourceCreates a new Phoenix project.
It expects the path of the project as an argument.
$ mix phx.new PATH [--module MODULE] [--app APP]
A project at the given PATH will be created. The
application name and module name will be retrieved
from the path, unless --module or --app is given.
Options
--umbrella- generate an umbrella project, with one application for your domain, and a second application for the web interface.--app- the name of the OTP application--module- the name of the base module in the generated skeleton--database- specify the database adapter for Ecto. One of:postgres- via https://github.com/elixir-ecto/postgrexmysql- via https://github.com/elixir-ecto/myxqlmssql- via https://github.com/livehelpnow/tdssqlite3- via https://github.com/elixir-sqlite/ecto_sqlite3
Please check the driver docs for more information and requirements. Defaults to "postgres".
--adapter- specify the http adapter. One of:cowboy- via https://github.com/elixir-plug/plug_cowboybandit- via https://github.com/mtrudel/bandit
Please check the adapter docs for more information and requirements. Defaults to "bandit".
--no-assets- equivalent to--no-esbuildand--no-tailwind--no-dashboard- do not include Phoenix.LiveDashboard--no-ecto- do not generate Ecto files--no-esbuild- do not include esbuild dependencies and assets. We do not recommend setting this option, unless for API only applications, as doing so requires you to manually add and track JavaScript dependencies--no-gettext- do not generate gettext files--no-html- do not generate HTML views--no-live- comment out LiveView socket setup in your Endpoint and assets/js/app.js. Automatically disabled if --no-html is given--no-mailer- do not generate Swoosh mailer files--no-tailwind- do not include tailwind dependencies and assets. The generated markup will still include Tailwind CSS classes, those are left-in as reference for the subsequent styling of your layout and components--binary-id- usebinary_idas primary key type in Ecto schemas--verbose- use verbose output-v,--version- prints the Phoenix installer version--no-version-check- skip the version check for the latest phx_new version--no-agents-md- do not generate anAGENTS.mdfile
When passing the --no-ecto flag, Phoenix generators such as
phx.gen.html, phx.gen.json, phx.gen.live, and phx.gen.context
may no longer work as expected as they generate context files that rely
on Ecto for the database access. In those cases, you can pass the
--no-context flag to generate most of the HTML and JSON files
but skip the context, allowing you to fill in the blanks as desired.
Similarly, if --no-html is given, the files generated by
phx.gen.html will no longer work, as important HTML components
will be missing.
Installation
mix phx.new by default prompts you to fetch and install your
dependencies. You can enable this behaviour by passing the
--install flag or disable it with the --no-install flag.
Examples
$ mix phx.new hello_world
Is equivalent to:
$ mix phx.new hello_world --module HelloWorld
Or without the HTML and JS bits (useful for APIs):
$ mix phx.new ~/Workspace/hello_world --no-html --no-assets
As an umbrella:
$ mix phx.new hello --umbrella
Would generate the following directory structure and modules:
hello_umbrella/ Hello.Umbrella
apps/
hello/ Hello
hello_web/ HelloWebYou can read more about umbrella projects using the official Elixir guide
PHX_NEW_CACHE_DIR
In rare cases, it may be useful to copy the build from a previously
cached build. To do this, set the PHX_NEW_CACHE_DIR environment
variable before running mix phx.new. For example, you could generate a
cache by running:
mix phx.new mycache --no-install && cd mycache && mix deps.get && mix deps.compile && mix assets.setup && rm -rf assets config lib priv test mix.exs README.md
Your cached build directory should contain:
_build
deps
mix.lockThen you could run:
PHX_NEW_CACHE_DIR=/path/to/mycache mix phx.new myapp
The entire cache directory will be copied to the new project, replacing any existing files where conflicts exist.