Change variables based on build options or build title possible?

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:

  1. Check the current page URL. If it starts with launch.playcanvas.com then set the variable to true
  2. Check URL params for debug
  3. 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
  4. 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.
  5. Use a service like https://playcanvas.redox-interactive.com/ to help do 3.

Great. Thanks for the ideas! :slight_smile:

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