I’m adding you guys to this question/request thinking that it’s something which bothered people not the first time, but before I will write a ‘feature request’, I want to check if it’s the best thing to do.
The problem is that very often clicking ‘Parse’-button gives an error:
Uncaught ReferenceError: document is not defined
from ‘assets-script-parse-worker.js’
I already realized that there is a possibility to add something like this at the beginning of the script:
if (typeof (document) !== "undefined") {
//script
}
The thing is, it’s not always possible to manually add it, while you are using additional libraries from NPM imported to the project, also minified and parsed by babel, thanks to templates like this one:
https://github.com/whydoidoit/babel-playcanvas-template
and automatically sent to the project. In live mode (local hosting) it works like a charm. But every time when you have to use the online (fully playcanvas.com hosted) version, with ‘ready to go’-built library, there’s the parser on your way. I’m assuming that it works as a node.js server or something like this and it doesn’t know what a global ‘document’ variable is.
To be more specific - I’m realizing, that there is no need to communicate with the ‘document’ or DOM at all in most cases. But more advanced projects nowadays are also using React, Angular, Vue, and many more. Any variables-store solution checks also from time to time some elements through ‘document’ variable. Standard GUI elements added to PC are often just not enough for our clients and thus we are forced to extend PC with one of those frameworks.
Checking big minified .js file and rewriting them is clearly not a solution. But maybe I missed something. Is there any possibility to add some global definition of ‘document’? If not, I think it is about time to add it to parser (feature request), because more and more complicated projects are made in less time every year, and slowly such things as automation and accepting big chunks of external code (which can base on standard browser definitions) are becoming a necessity.