Hi.
I am working on a medium-sized Phoenix application. We have seen the compile times rise as we add more and more features to the application.
Some time ago I equipped myself with the improved mix xref
that came with Elixir 1.6 and started to make sense of the module interdependencies that were causing our slow compile times.
Many of those have been already fixed, and compilation times have improved accordingly. I started working in the problems that slowed the compilation more, and there are still some other fixes to work on.
There is still a problem that I initially though was a low hanging fruit easy to fix, but it is giving me headaches.
In our web.ex
file we have the following:
def view do
quote do
use Phoenix.View, root: "web/templates", pattern: "**/*"
end
end
This pattern
is telling Phoenix views to compile the templates in their corresponding directory AND all its subdirectories recursively. Due to the organization of our application in nested modules, there are many templates being compiled multiple times by views that never call them.
I am looking on optimising this. I know that by default phoenix uses the "*"
pattern, which means that views only compile templates in the corresponding directory, but not in subdirectories.
Since we have many helper templates, I would prefer to have them stored in a component
subdirectory (one for each view, that has the required helper templates). So I would have:
web/templates/my_view/component/table_header.html
web/templates/my_view/table.html
instead of
web/templates/my_view/_component_table_header.html
web/templates/my_view/table.html
The thing is, I donāt know how to make Phoenix views to compile templates in their corresponding directory AND in the component
subdirectory.
Iāve tried multiple glob expressions. The last one being pattern: "{{.,component/**}/*"
but I receive an (ErlangError) Erlang error: {:badpattern, :missing_delimiter}
error.
Do you have any ideas?