I was wondering if there was a way I can change variables based on the title of the build or in some other way external to the compiled code. For example it would be good if my ‘show_debug’ variable is set to true if the build title contains the word ‘debug’.
Or maybe there is some other way I can do this that already exists?
Not part of our build system, no.
There are a couple of ways you could do this:
- Check the current page URL. If it starts with launch.playcanvas.com then set the variable to true
- Check URL params for debug
- Create a release branch that only has the change of this variable set to false. And merge your development branch to it before building a release
- Have debug code between comments blocks like
// DEBUG_START
and // DEBUG_END
. Don’t minify your code on publish and use a post build script that takes the __game-scripts__.js
file, strips code out between those comment blocks and minifies the code.
- Use a service like https://playcanvas.redox-interactive.com/ to help do 3.
Great. Thanks for the ideas! 
For future reference the final code for checking against current url is:
//get current url
var url = new URL(window.top.location.href);
//check if current url contains "launch.playcanvas.com" or whatever you want
this.is_hosted_on_playcanvas=url.toString().includes("launch.playcanvas.com");
//Show debug only if we are hosted at Playcanvas
if(this.is_hosted_on_playcanvas==false)
{
this.show_debug=false;
}
2 Likes