// Builds release/robotclash.html: the whole game in ONE file. Local s.replace(/<\/script/gi, '<\\/script');
html = html.replace(//g, (m, p) =>
local(p) ? `` : m);
// optional: run each own script through terser (mangle locals, compress) -> harder to read.
// Enabled with RC_OBFUSCATE=1 (build.ps1 -Obfuscate). vendor/three.min.js is already minified -> skip.
const obf = process.env.RC_OBFUSCATE === '1';
let terser = null;
if (obf) {
try { terser = await import('terser'); }
catch { console.error('RC_OBFUSCATE=1 but terser is missing - run: npm install'); process.exit(1); }
}
const minify = async (code, name) => {
if (!terser || /vendor\/three/.test(name)) return code;
const r = await terser.minify(code, { compress: true, mangle: true, format: { comments: false } });
if (r.error) { console.error(`terser failed on ${name}:`, r.error); process.exit(1); }
return r.code;
};
const scriptJobs = [];
html = html.replace(/`]));
return token;
});
for (const [token, tag] of await Promise.all(scriptJobs)) html = html.replace(token, () => tag);
// static references in CSS / HTML attributes
html = html.replace(/url\((['"]?)(assets\/[^'")]+)\1\)/g, (m, q, p) => (assets[p] ? `url('${assets[p]}')` : m));
html = html.replace(/(src|href)="(assets\/[^"]+)"/g, (m, a, p) => (assets[p] ? `${a}="${assets[p]}"` : m));
// everything the scripts load at runtime: must come before the first other \n