I have an Elixir module that contains a demo that I use in development and for integration testing with other systems. I do not want that module to be compiled for the prod environment. Is there some cute trick with mix/config I can use to make sure this module is unavailable in certain contexts?
The way Phoenix solves this problem is by specifying different value for elixirc_paths in mix.exs for different environments. Here's how you can achieve that:
def project do
[
..,
elixirc_paths: elixirc_paths(Mix.env),
..,
]
end
defp elixirc_paths(:prod), do: ["lib"]
defp elixirc_paths(_), do: ["lib", "not-prod"]
Now put your .ex files that you want to not be present in :prod inside /not-prod/ (You might want to use a better name for this...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With