How to make a module reload when changed?

I have a phoenix project on Elixir 1.4.2, which loads a package with path: like following:

defp deps do
    {:a_package, path: "../../a_package", runtime: false},

The package has several files. When I modify a file in the package, is there any way to make the phoenix project reload it, not only with reloading the phoenix but also reloads it automatically?

Dependencies are expected to be static, so that is definitely not a usual use-case. ^.^

You ‘might’ be able to be changing the watched paths for the phoenix reloader to that path as well, but that reloader only does the equivalent of calling mix compile I think, which will not recompile a dependency automatically either.

You could make it an umbrella project and make both parts of the umbrella?

Maybe others have ideas too?

Make an alias which updates that dep, recompiles it and then compiles your project.

Would not work for auto-reloading I think, that still requires it to be manually done?

I haven’t seen the requirement of auto reload. Afaik that’s only possible under an umbrella.

1 Like

I’m afraid but as the modules is used from several different phoenix projects, I cannot make it into the umbrella…

Is there any documents about how to configure phoenix reloader? I browsed Phoenix.CodeReloader, but I cannot found the way.

Then you are out of luck.

Even if you were able to change the pathes which are watched, only mix compile were called, but you need to call mix do deps.update $yourdep, deps.compile, compile. And even when you do the latter, I’m not even sure if that fresh compiled modules are reloaded then, or that of the app only. After compilation they live in different areas of your _build folder.

A dependency shouldn’t change that often, and if you change your dep more often than the core, then your dependency is propably not a dep, but your application in which case you should either integrate it or make it an umbrella.


This is old, but I am developing a package and it’s so annoying that I have to restart the Phoenix server each time I make a change in the package code.

I am having an hard time believing that when Jose, Chris and others from the core team have to develop a package, that they have to keep restarting the server to see the code changes applied.

So I am curious to know what is the workflow that package developers use in order to avoid this big annoyance?

I include the package like this:

{:utils_for, path: "./.dev-bench/utils_for"}

Take a look at LiveDashboard. It starts a phoenix server in the project itself for development.

1 Like

Thanks for the tip.

It seems to me that what you mention may be useful for developing the package in isolation, but I am developing it while using it for real in my application, that already has a running server.

I’ve made the umbrella app and then create a symlink from package directory to umbrella apps:
ln -s ~/Dev/my_package ~/Dev/my_demo_umbrella/apps/my_package

With this setup code reloading works somehow even without dependency in other apps mixfiles.

Almost 3 years later but @focused or @Exadra37 did you find a better solution for this?
What we are doing now is creating a symlink of our package directory in deps ln -s ~/dev/my_package ~/dev/my_app/deps/my_package and then setup the path dependency to the symlink like {:my_package, path: "deps/my_package"} and then in mix file we added it as an elixir path for dev only defp elixirc_paths(:dev), do: ["lib", "deps/my_package/lib"] with this we are getting the deps changes in elixir files reflected in our app without restarting the server.

If not mistaken I just end-up to develop the package inside lib folder, but I think my first approach was to add the package paths to the reload config.

If you add the app name to reloadable_apps in your Endpoint config then the path dependency will be reloaded when you reload the page: Phoenix.CodeReloader — Phoenix v1.6.16

1 Like

That’s great @axelson! it worked like a charm! Thanks

1 Like