Gigitsu

Gigitsu

Phoenix code reload in umbrella with multiple app

I have an umbrella project with multiple apps. Two are just libraries with utilities and shared code, while the others are Phoenix applications that can be served.

For instance:

Umbrella app
├── core (shared library)
├── common (shared library)
│   
├── backoffice (phoenix app)
│   depends on
│   ├── common (in umbrella)
│   └── core (in umbrella)
├── frontend_1 (phoenix app)
│   depends on
│   ├── common (in umbrella)
│   └── core (in umbrella)
├── frontend_2 (phoenix app)
│   depends on
│   ├── common (in umbrella)
│   └── core (in umbrella)

During my development process, I need to start one Phoenix app at a time, and I do this with:

mix do --app backoffice cmd mix phx.server

But in this way, if I change something in core or common, the code is not hot reloaded and I need to restart the server for the changes to take effect.

How can I fix this? Can I start the server from the umbrella root but selecting only one app?

Most Liked

hubertlepicki

hubertlepicki

Hang on @Gigitsu I have you covered with my own contribution to Phoenix xD.

Check out the :reloadable_apps option that I added to Phoenix a while ago. My use case was similar but not identical, so I am wondering if it will work for you.

config :your_app, Backoffice.Endpoint,
  reloadable_apps: [:frontend_1, :frontend_2, :backoffice, :core, :common]
Gigitsu

Gigitsu

Thanks @samaravilha.

I’ve managed to get code reload working by adding the following configurations in my dev.exs file

config :phoenix_live_reload, :dirs, [
  Path.expand("../apps/my_app", __DIR__),
  Path.expand("../apps/common", __DIR__),
  Path.expand("../apps/core", __DIR__)
]
config :my_app, MyApp.Endpoint,
  live_reload: [
    patterns: [
      ~r"../common/lib/common/(\w+/)*.*(ex|heex)$",
      ~r"../core/lib/core/(\w+/)*.*(ex|heex)$",
      ~r"priv/gettext/.*(po)$",
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"lib/my_app/(controllers|live|components)/.*(ex|heex)$"
    ]
  ]
config :my_app, MyApp.Endpoint,
  ...
  reloadable_apps: [:my_app , :core, :common],
  ...

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement