@import or require() Javascript

I’m wondering if there’s a Sage way of reducing the length of my JS files. Currently, I use the main.js as included in Sage, and I love the way it divides your code into sections for each page. However, as my code grows, it would be amazing if there was a way to @import or require() sections of code, like in SCSS or PHP. I understand that gulp can combine and minify your JS, but is there a way of including your JS from right inside those ‘page sections’? Any thoughts?

You would have to use Webpack. Sage 9 is going to be released soon, so I would recommend looking into using Sage 9 as it supports this.

1 Like

Also recent webpack supports tree shaking.