#shortnotes: Brunch+Phoenix: Getting through the mess

Brunch is a RAD build tool that comes by default when you install phoenix.

I’ve been skimming through several brunch related issues in github, “Page Specific Javascript” and “Requiring a script on a particular page” that have been helpful.

There may be more than one way to do things here, but this is what worked for me.

Given a javascript file you’ve written in the web/static/ location in, say any other directory than js, say web/static/registration/ such as:

with a brunch configuration like this:

Notice L62. That made all the difference!

If I were to load this with require in the web/views/PageView.ex of that specific page, somehow this wasn’t working:

~s{<script>require(“priv/static/js/registration”)</script>} |> raw

maybe it’s an internal versioning error or something not imported.

Instead I had to make sure I do this:

This executed the specific JS script in the specific PageView

Just getting the right brunch config (in this case set the autoRequire for that module) is important!