Can someone please help me with the scripts loading order on the build? For me it’s not making any sense! (I’m using web-mobile build to test it) On preview it works fine, this problem are only on builds
Before the 2.4, the scripts could be in any place of the project, but now it seems that the folder makes a lot of difference in the loading order!
What I noticed so far
Plugins should be loaded first, but they will not if they are in resources folder, they will load as a normal script
The normal scripts will run the require as soon as they are loaded, so it will crash if it requires another script that was not loaded yet
1st, There is a race condition in plugins / normal scripts loading, the plugins are not ensured to be loaded and runned before the normal scripts being loaded/runned. So, if you have a lot of plugins, even on the root of the project, some normal scripts can start running before they ended running the plugins.
In my case, when I putted all the scripts that defined global variables in the same folder, when the first normal script runned, the “const asd = require(window.Defs.ASD)” broke because Defs was not defined. It would be defined in the 10th plugin to be loaded, but only 5 were loaded at this point.
2nd, in top of the previous problem, the resources folder will only be loaded after all of this, so if you have any script there, they will be loaded after.
Here some example for you, if you run the build, you will see.