Octopus package steps have a feature that allows you to replace Octopus Variables in any file.

Great, but I use that in JavaScript it needs to work locally before any octopus magic happens. So I use this:

var baseUrl = octoTemplate("#{portalUri}", "http://localhost:4200/");

....

function octoTemplate(value, fallback) {
    if (value.substr(0, 2) === "#{") {
        return fallback;
    }

    return value;
}