Created
March 28, 2025 10:01
-
-
Save luminarious/4eda9cb75909b44e3ad30c9b5f6114b4 to your computer and use it in GitHub Desktop.
Measure if final compressed build is under 13KB (originally meant for js13k game competition)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const archiver = require('archiver') | |
const MAX = 13 * 1024 // 13kb | |
const output = fs.createWriteStream(`${__dirname}/dist/build.zip`) | |
const archive = archiver('zip', { | |
zlib: { level: 9 } // set compression to best | |
}) | |
archive.pipe(output) | |
archive.glob('**/!(*.map|*.zip)', { cwd: './dist' }) | |
archive.finalize() | |
output.on('close', () => { | |
const bytes = archive.pointer() | |
const percent = (bytes / MAX * 100).toFixed(2) | |
if (bytes > MAX) { | |
console.error(`Size overflow: ${bytes} bytes (${percent}%)`) | |
} else { | |
console.log(`Size: ${bytes} bytes (${percent}%)`) | |
} | |
}) | |
archive.on('warning', (err) => { | |
if (err.code === 'ENOENT') { | |
console.warn(err) | |
} else { | |
throw err | |
} | |
}) | |
archive.on('error', err => { | |
throw err | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment