mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Add MINIFY_SYNTAX flag in build.ts
This commit is contained in:
parent
1b2cf70248
commit
4271583a5a
12
build.ts
12
build.ts
@ -20,6 +20,8 @@ enum BuildTarget {
|
|||||||
|
|
||||||
type BuildVariant = 'full' | 'lite';
|
type BuildVariant = 'full' | 'lite';
|
||||||
|
|
||||||
|
const MINIFY_SYNTAX = true;
|
||||||
|
|
||||||
const postProcess = (str: string): string => {
|
const postProcess = (str: string): string => {
|
||||||
// Unescape unicode charaters
|
// Unescape unicode charaters
|
||||||
str = unescape((str.replace(/\\u/g, '%u')));
|
str = unescape((str.replace(/\\u/g, '%u')));
|
||||||
@ -70,9 +72,6 @@ const postProcess = (str: string): string => {
|
|||||||
// Collapse empty brackets
|
// Collapse empty brackets
|
||||||
str = str.replaceAll(/\{[\s\n]+\}/g, '{}');
|
str = str.replaceAll(/\{[\s\n]+\}/g, '{}');
|
||||||
|
|
||||||
// Collapse if/else blocks without curly braces
|
|
||||||
str = str.replaceAll(/((if \(.*?\)|else)\n\s+)/g, '$2 ');
|
|
||||||
|
|
||||||
// Remove blank lines
|
// Remove blank lines
|
||||||
str = str.replaceAll(/\n([\s]*)\n/g, "\n");
|
str = str.replaceAll(/\n([\s]*)\n/g, "\n");
|
||||||
|
|
||||||
@ -91,10 +90,15 @@ const postProcess = (str: string): string => {
|
|||||||
// str = str.replaceAll(/ \(([^\s,.$()]+)\) =>/g, ' $1 =>');
|
// str = str.replaceAll(/ \(([^\s,.$()]+)\) =>/g, ' $1 =>');
|
||||||
|
|
||||||
// Set indent to 1 space
|
// Set indent to 1 space
|
||||||
|
if (MINIFY_SYNTAX) {
|
||||||
|
// Collapse if/else blocks without curly braces
|
||||||
|
str = str.replaceAll(/((if \(.*?\)|else)\n\s+)/g, '$2 ');
|
||||||
|
|
||||||
str = str.replaceAll(/\n(\s+)/g, (match, p1) => {
|
str = str.replaceAll(/\n(\s+)/g, (match, p1) => {
|
||||||
const len = p1.length / 2;
|
const len = p1.length / 2;
|
||||||
return '\n' + ' '.repeat(len);
|
return '\n' + ' '.repeat(len);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
assert(str.includes('/* ADDITIONAL CODE */'));
|
assert(str.includes('/* ADDITIONAL CODE */'));
|
||||||
assert(str.includes('window.BX_EXPOSED = BxExposed'));
|
assert(str.includes('window.BX_EXPOSED = BxExposed'));
|
||||||
@ -128,7 +132,7 @@ const build = async (target: BuildTarget, version: string, variant: BuildVariant
|
|||||||
outdir: outDir,
|
outdir: outDir,
|
||||||
naming: outputScriptName,
|
naming: outputScriptName,
|
||||||
minify: {
|
minify: {
|
||||||
syntax: true,
|
syntax: MINIFY_SYNTAX,
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user