How do I recompile an Elixir project and reload it from within iex?

KallDrexx picture KallDrexx · Apr 8, 2016 · Viewed 27.2k times · Source

I'm currently learning Elixir by going through the OTP and mix tutorial on the elixir-lang website, and I'm having trouble finding out how to recompile and reload the project from within the shell.

In Erlang I would do make:all([load]) and it would compile and load any changes that occurred. However, in iex that always says :up_to_date, which does make sense, as Elixir uses mix for it's compiling needs.

I can't find any equivalent from within iex.

Answer

Dogbert picture Dogbert · Apr 8, 2016

You can use the IEx.Helpers.recompile/0 function.

Recompiles the current Mix application.

This helper only works when IEx is started with a Mix project, for example, iex -S mix. Before compiling the code, it will stop the current application, and start it again afterwards. Stopping applications are required so processes in the supervision tree won't crash when code is upgraded multiple times without going through the proper hot-code swapping mechanism.

Changes to mix.exs or configuration files won't be picked up by this helper, only changes to sources. Restarting the shell and Mix is required in such cases.

If you want to reload a single module, consider using r ModuleName instead.

NOTE: This feature is experimental and may be removed in upcoming releases.

From https://github.com/elixir-lang/elixir/blob/v1.2.4/lib/iex/lib/iex/helpers.ex#L56-L93