Hello there!
This should be quite a straightforward question for those who have more knowledge about how Elixir compiles our files
I have a module where I want to compile (or not) some imports depending on the environments I’m using (dev
, test
, prod
).
Why do I want that? Because if I don’t do it, Elixir will show some ugly warnings during my compilations.
The code looks like this:
defmodule MyApp do
@moduledoc false
if Mix.env() == :dev do
def fun(a,b), do: a
else
import Phoenix.LiveView
def fun(a,b) do
# use any LiveView functions here
end
end
end
This code works so, what’s the problem here?
Even if I’m in dev
environment, I get the compiler warning saying that the import is not getting used. Same thing happens if instead of an import I have an alias not used.
What can I do (if it’s possible) to avoid these warnings in dev
env?
As far as I know the compiler should not execute that part of the code.
Thanks in advance!