How to do a live reload on file change with custom compiler

Hi

I’m currently trying to get a custom compiler to compile some templates for web components into a large file, so that I can include those in the main app.html.eex layout.

At the moment I’ve simply added an alias for the compile task that runs a simple bash script and does exactly what I want, however the annoying thing is that if I make a change in one of the template files I need to manually trigger the recompile to deliver the changes to the client.

If been looking around for a bit, but so far I’ve not found a simple solution to simply add those files to a watch list for the compiler (elixir of phoenix compiler). Any hints on how to achieve this? I.e. trigger a recompile and phoenix live reload once I change such a file.

That should work fine then as long as the watcher files are listed there.

So, did you make a new elixir compiler and added it to the front of the compiler list? Or did you just make a new task (which will not work for this)?

If you are just wanting to run a script when something changes then add it as a new watcher for phoenix and that would work then, but it won’t compile at compile-time (like for a release) so you’d want to keep that task. Might be easier just to make an elixir compiler plugin thoguh.

Any file they get compiled ‘into’ you will want to reference it via @external_resource (which is generally wrapped up in a macro or so anyway for usage) to make sure recompiles happen properly.

2 Likes

Thanks, I’ve got it working now. Basically I wasn’t aware that we can define more watchers in the endpoint config :slight_smile:

1 Like