Great, glad you got it working!
You’re right about it being a challenge to handle the JS lifecycle. On my current project, I’ve actually temporarily disabled Barba.js because it was causing a lot of problems and it isn’t a major priority to have it working for the final site.
It’s not really a fault of Barba.js but rather the rest of the WordPress setup - this site has some Revolution Sliders and they inject inline script blocks into the HTML but they never get executed when loaded via AJAX. There are probably ways around it but I’m hoping to convince everyone that we don’t actually need this monster plugin… The other problem I had was with Elementor because it has page-specific CSS files that it generates and these would need to be injected or embedded directly into the page content.
So for now Barba.js is on the back-burner but I would like to get it working at some point. I read the section about using Views and what you’re saying should be fine - as long as the
Barba object is properly imported and in an available scope, you should be able to use it in those other files. There are probably several ways you could structure it but on first look, using the Sage routing seems to make sense.
Since I haven’t gone deep enough into using Barba.js, I’m not the best one to answer these questions but you could try reaching out to @kaisermann or @mikespainhower since they have both used Barba.js on sites they’ve developed…
On the topic of Webpack, this might help to understand how it all fits together: