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.

Last Post!

axelson

axelson

Scenic Core Team

Yeah I don’t think reloadable_apps existed at that time. But it is definitely a great to have available to you! Although a small note is that it doesn’t change the behavior of the IEx.Helpers.recompile command, instead you’ll have to be sure that you trigger Phoenix.CodeReloader (which is separate from phoenix_live_reload) by reloading a page in your Phoenix app.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
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

We're in Beta

About us Mission Statement