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?
1 Answer
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...).