Skip to content

Commit c56b49c

Browse files
committed
build: fix size display
1 parent 1027862 commit c56b49c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

build.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ const logger = new Logger('build');
1010
logger.info('Building...');
1111

1212
function encodeBinary(a: Buffer) {
13-
const file = zlib.gzipSync(a);
13+
const file = zlib.gzipSync(a, { level: 9 });
1414
return chunk([...encode(file)], 1000).map((i) => String.fromCodePoint(...i)).join('');
1515
}
16+
function size(a: string) {
17+
return `${Math.floor((Buffer.from(a).length / 1024 / 1024) * 10) / 10}MB`;
18+
}
1619

1720
const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==';
1821

@@ -28,14 +31,16 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
2831
minify: true,
2932
entryPoints: [path.resolve(process.cwd(), 'packages/server/index.ts')],
3033
charset: 'utf8',
31-
sourcemap: 'inline',
34+
sourcemap: process.argv.includes('--debug') ? 'inline' : false,
3235
plugins: [{
3336
name: 'base16384',
3437
setup(b) {
3538
b.onLoad({ filter: /\.(frontend|ttf|wasm)$/, namespace: 'file' }, (t) => {
3639
const file = fs.readFileSync(path.join(t.path));
40+
const contents = `module.exports = "${encodeBinary(file)}";\n${nopMap}`;
41+
console.log(t.path, size(contents));
3742
return {
38-
contents: `module.exports = "${encodeBinary(file)}";\n${nopMap}`,
43+
contents,
3944
loader: 'tsx',
4045
};
4146
});
@@ -52,7 +57,7 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
5257
});
5358
if (res.errors.length) console.error(res.errors);
5459
if (res.warnings.length) console.warn(res.warnings);
55-
logger.info(`Resource Size: ${Math.floor((res.outputFiles[0].text.length / 1024 / 1024) * 10) / 10}MB`);
60+
logger.info(`Resource Size: ${size(res.outputFiles[0].text)}`);
5661
fs.writeFileSync(path.resolve(process.cwd(), 'dist/xcpc-tools.js'), res.outputFiles[0].text);
5762
logger.info('Saved to dist/xcpc-tools.js');
5863
})();

0 commit comments

Comments
 (0)