How to Minify and Optimize JavaScript in Magento 2

javascriptmagento2

I've been struggling for a while with minify javascript on magento 2. The admin option for minification doesn't work so I've been looking for another solution. I've tried a gulp script to do it but this is causing issues with require js where certain files are not ready in time to be included.

Has anyone found a solution for minifying javascript on magento 2?

Best Answer

In the end we used a gulp script we wrote ourselves that looks for every javascript file and minifies it. Looks like this is the only way to do it for now without dealing with the bugs the built in magento config option has.

This was our eventual gulp file solution: https://gist.github.com/lewisp6/b7c50b4d82ef4d3d5d6dc888e8d1bdba

Related Topic