(I have looked at related answers, they provide no help because they make invalid assumptions.)
I'm working on a job where the front-end is component-based. I have no control over this. Some of the front-end requires JS and, if it doesn't load last, it screws up all the Drupal JS.
I need to force these three front-end JS files to load last and I would prefer to do it legally.
I have tried hacking the weights in
js_alter() but apart from being a bad idea (it's not advised) it does not seem to have any effect.
I've tried setting the weights in the
theme.libraries.yml file but it's impossible to set the weights to enforce what I need. (Set them too heavy and you get an exception.)
My final solution is to force the front-end theme library to be dependent on every Drupal library it conflicts with.
This works, BUT it forces the drupal JS to load on pages where it's not needed (because the theme JS is needed on every page*).
*Technically it's not needed on every page but I am not in a position to request the front-end guys write their code better...