Phoenix v1.4.9 mix phx.new View Source

Creates 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 (https://github.com/elixir-ecto/postgrex)
    • mysql (https://github.com/elixir-ecto/myxql)

    Please check the driver docs, between parentheses, for more information and requirements. Defaults to "postgres".

  • --no-webpack - do not generate webpack files for static asset building. When choosing this option, you will need to manually handle JavaScript dependencies if building HTML apps

  • --no-ecto - do not generate Ecto files.

  • --no-html - do not generate HTML views.

  • --binary-id - use binary_id as primary key type in Ecto schemas

  • --verbose - use verbose output

When passing the --no-ecto flag, Phoenix generators such as phx.gen.html, phx.gen.json 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.

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-webpack

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/    HelloWeb

You can read more about umbrella projects using the official Elixir guide

To print the Phoenix installer version, pass -v or --version, for example:

mix phx.new -v

Link to this section Summary

Functions

A task needs to implement run which receives a list of command line args.

Link to this section Functions

Link to this function

generate(base_path, generator, path, opts) View Source

A task needs to implement run which receives a list of command line args.

Callback implementation for Mix.Task.run/1.

Link to this function

run(argv, generator, path) View Source