michaelterryio

michaelterryio

Make `recompile` work with dependency

Hey,

I’ve got a project with several path dependencies. Some are phoenix apps, but this likely isn’t relevant.

I don’t fully understand the following behavior.

If I make a change in a file in a path dependency and run iex -S mix phx.server, the file is recompiled.

But if I make a change in a file in a path dependency while iex is already running, the file is not recompiled.

I know I can use r() on a particular module, but that’s not quite as convenient. Is there an easy way to get recompile to work on changed files in path dependencies?

Most Liked

axelson

axelson

Scenic Core Team

You could try out exsync for your code reloading:

It will recompile path dependencies for you when you make the changes.

delameko

delameko

As this is a top result on Google when searching for auto recompiling dependencies, I just wanted to leave a solution that doesn’t require a third party library (not sure if this was possible when the question was originally asked). This is for Phoenix apps running live_reload, if not, then exsync is still a good option.

You’ve got two projects my_app and my_dep. In my_app/mix.exs you’ve got:

    defp deps do
      {:my_dep, path: "../my_dep"}
      ..
    end

In your config/dev.exs:

    config :my_app, MyApp.Endpoint,
      live_reload: [
        patterns: [
          # make sure you have patterns that work for either app, they should be relative 
          # to the root of a project, the same pattern can match both apps. 
          # So don't do '~r"../core_dep/priv"', that'll be ignored, do: '~r"priv"'
        ]
      reloadable_apps: [:my_dep, :my_app]

and

    parent_path =
      __ENV__.file
      |> Path.dirname()
      |> Path.join("../..")
      |> Path.expand()

    config :phoenix_live_reload, :dirs, [
      Path.join([parent_path, "my_dep"]),
      Path.join([parent_path, "my_app"])
    ]

Now your webpage update with changes made to either app.

NobbZ

NobbZ

Recompile does only ever recompile modules of the current application/project.

In my opinion, you should not rely on anything to recompile your dependencies, except for mix deps.compile --force.

Where Next?

Popular in Troubleshooting Top

alexlanderzander
Hello everyone, I’m working on a blockchain project in Elixir and I’m implementing some of the core cryptography in a Rust NIF using Rus...
New
chocolatedonut
Besides (over)logging every code-path leading to Repo.insert_all, is it possible to make Postgrex and/or ecto_sql log the exact, failing ...
New
mohammedzeglam
I am trying deploy phoenix app to cloud run every thing works locally fine using public IP but when i deployed to cloud run the app could...
New
runyonave
We have been stuck on this for a few days now and I am really not sure what could be missing. I can get chromic_pdf to work perfectly fin...
New
pikdum
Hello, I’m trying to upgrade a pretty large project from Elixir 1.18.4 to Elixir 1.19.1 (1321 modules), but seeing some compiler warning...
New
michaelterryio
Hey, I’ve got a project with several path dependencies. Some are phoenix apps, but this likely isn’t relevant. I don’t fully understand...
New
arnoldwolfe
I’ve been unable to deploy apps for over a week now due to the following error. It all started when Github has issues with GitHub Actions...
New
klo
Is there any way to go from a float 1.0 to 1.00 while retaining the float() type?
New
rayex
Hi, I am using the following versions: Erlang/OTP 27 [erts-15.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns] El...
New
apoorv-2204
The Issue of Enums in Elixir Elixir doesn’t have a native enum construct, so we usually rely on atoms, strings, or macros to represent na...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
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...
273 38985 115
New

We're in Beta

About us Mission Statement