Phoenix.CodeReloader
A plug and module to handle automatic code reloading.
For each request, Phoenix goes through all modules and checks if any of them implement a __phoenix_recompile__?/0 function. If they do and it returns true, the module source file is touched, forcing it to be recompiled. For this functionality to work, Phoenix requires you to add the :phoenix compiler to your list of compilers:
compilers: [:phoenix] ++ Mix.compilers()
This is useful, for example, to recompile modules that depend on external systems, such as directories, databases, etc. Note if you simply depend on external files, @external_resource annotation should be used.
To avoid race conditions, all code reloads are funneled through a sequential call operation.
Summary
Functions
- call(conn, opts)
API used by Plug to invoke the code reloader on every request.
- init(opts)
API used by Plug to start the code reloader.
- reload!(endpoint)
Reloads code for the current Mix project by invoking the
:reloadable_compilerson the list of:reloadable_apps.
Functions
call(conn, opts)
API used by Plug to invoke the code reloader on every request.
init(opts)
API used by Plug to start the code reloader.
reload!(endpoint)
Specs
reload!(module()) :: :ok | {:error, binary()} Reloads code for the current Mix project by invoking the :reloadable_compilers on the list of :reloadable_apps.
This is configured in your application environment like:
config :your_app, YourApp.Endpoint, reloadable_compilers: [:gettext, :phoenix, :elixir], reloadable_apps: [:ui, :backend]
Keep in mind :reloadable_compilers must be a subset of the :compilers specified in project/0 in your mix.exs.
The :reloadable_apps defaults to nil. In such case default behaviour is to reload current project if it consists of single app, or all applications within umbrella project. You can set :reloadable_apps to subset of default applications to reload only some of them, empty list - to effectively disable code reloader, or include external applications from library dependencies.
© 2014 Chris McCord
Licensed under the MIT License.
https://hexdocs.pm/phoenix/Phoenix.CodeReloader.html