TIL about the @external_resource module attribute in Elixir

Today I learnt about the @external_resource module attribute in Elixir.

From the Module documentation page:

Sometimes a module embeds information from an external file. This attribute allows the module to annotate which external resources have been used.

Tools like Mix may use this information to ensure the module is recompiled in case any of the external resources change.

@external_resource means that you can specify a resource outside of your module that will trigger recompilation of your module - basically, it sets up a dependency between your module and another file.

Eric Oestrich blogged about a real-life use-case for this feature - generating functions based on an external "translations" file. At compile-time he reads the file and generates functions based on it. His post goes into a lot more depth and has code examples. I recommend giving it a read.