Should priv/static/js/ files be in the git repository or should I build on deploy?

I’m using Webpack to compile my javascript assets into a single file:

/priv/static/js/app.js

And it works fine locally and on Heroku. The problem is that every time someone writes new javascript, the app.js file is radically different and that means almost every time we pull there’s a merge conflict in this compiled javascript file.

This leads me to believe we’re not doing things the right way.

I think what needs to happen is I need to remove the end result app.js file from my Git repository, and only keep the source JS files in the repo.

The assets should probably be built on-deploy to Heroku as well.

Does anyone have experience with Phoenix/Webpack for this problem?

Yes, don’t put your compiled app.js into your repo.

3 Likes

Can you recommend a guide or article on how to compile Webpack assets on deploy for a Phoenix app?

There are many ways to accomplish this, it really depends on where you are deploying as well.

Maybe some more background on your current deployment system would help.

You could use Docker for example, or a PaaS solution.

I’m hosting it on a Heroku free-tier dyno with the Elixir Heroku buildpack:

The project is using Webpack 3, and basically right now it compiled everything down into a single app.js file located in:

/priv/static/js/app.js

So right now I have this compiled app.js in the code repository, but I want to remove it and compile it on deploy so the JS is compiled on the Heroku side.

Appreciate the help!