Force re-build the entire project (or a better option?)

I am using a phoenix app which uses ex_gram library. It basically talks to telegram via HTTP.

When I change something in my bot.ex file (which has functions which make HTTP calls for me) , I cannot see the changes until I restart my phoenix server.

Sometimes, I stop and start the server and things work just fine.

On other occasions I run, rm -rf _build and then rebuild the entire project. (takes 4 minutes or so)

Is there a way to watch the changes in my bot.ex and file and recompile ONLY that file?

Which Elixir version are you using?

erlang 24.1.4
elixir 1.13.0-rc.0-otp-24

If You start the server through iex, then You can recompile…

How do You start it?

Where did You put the file? If it is a custom place… the reloader won’t be catched. See in your dev config the reload patterns.

mix phx.server is how I start the server.

I put the file in MyApp directory (not MyAppWeb) generated by phoenix mix phx.new

Can I specify this file to be watched in dev.exs?

Try to start the server with…

iex -S mix phx.server

This will give You access to iex console, while the server is running. In case, type recompile :slight_smile:

You can also update reload patterns in config/dev.exs, because MyApp is not watched.

3 Likes

IsMyAppWeb watched for changes?

Will try this solution and revert.

This is my first time seeing a command mixing two (iex and phx.server)
:slight_smile:

So it means You have never seen the observer :slight_smile:

Try it from the console of the running server…

:observer.start()
1 Like

If you really need to you can just rm -rf _build/dev/lib/<your_app> only.

This should work automatically as Phoenix should recompile the project on requests. When this does not work, it is usually because there is another tool, like a mix watcher or similar, running in the background that is compiling the files behind the scenes, so Elixir don’t see them as stale.

It may also happen if your files are in a separate filesystem that does not track modification times correctly (such as network based ones).

In a default Phoenix app, changes to files in lib/my_app_web/(live|views)/.*(ex)$ & lib/my_app_web/templates/.*(eex)$ will trigger a live reload. Files under lib/my_app usually will not.

When I add or modify files outside of the two locations above, I just use recompile in iex to recompile the mix application

See recompile/1 in the IEx docs for details :slight_smile:

2 Likes

WHere is this lib/my_app_web/(live|views)/.*(ex)$ & lib/my_app_web/templates/.*(eex)$ defined?

Can i set watch certain files inmy_app for recompilation?

It is defined in your dev.exs file, near to line 63, you will find many patterns defined for

config :my_app_web, MyAppWeb.Endpoint,
  live_reload: [
    patterns: [
       ...
    ]
]
3 Likes

added my file to this and works like charm!

Thank you so much everyone!