Search code examples
phoenix-frameworkumbrella

Is there a right way to change a non umbrella project to use umbrella feature with Phoenix framework?


Using Phoenix framework now. At the beginning, we didn't use --umbrella option to generate the project. So the structure is like a simple app of umbrella way.

Now want to change the project to the umbrella way. Is it possible and how to do?


Solution

  • As of phoenix 1.3 and elixir 1.5:

    Generate a fresh umbrella app in a separate directory:

    $ mix new my_umbrella --umbrella
    

    Move your phoenix application to the apps/ directory in the new umbrella directory:

    $ mv /path/to/my_app /path/to/my_umbrella/apps/
    

    Your build path, deps folder, and main config and mix files now live in the root of the umbrella. You'll need to add the following lines to your project function in your phoenix mix.exs to point to the right locations as below:

    # my_umbrella/apps/my_app/mix.exs
    
    def project do
      [
        # ...
    
        build_path: "../../_build",
        config_path: "../../config/config.exs",
        deps_path: "../../deps",
        lockfile: "../../mix.lock",
    
        # ...
      ]
    end
    

    Refetch your dependencies from the root of the umbrella.

    $ mix deps.get
    

    Assuming you're using brunch, you'll also need to edit the assets/package.json file in your phoenix app folder to point to the correct location for deps/:

    // my_umbrella/apps/my_app/assets/package.json
    "phoenix": "file:../../../deps/phoenix",
    "phoenix_html": "file:../../../deps/phoenix_html"
    

    You may need to refresh the package-lock.json file to re-run npm install command if using a recent version of npm.

    From the root of the umbrella, you should be able to start your phoenix server.

    $ mix phx.server