Skip to content

Instantly share code, notes, and snippets.

@luminarious
Created March 28, 2025 10:01
Show Gist options
  • Save luminarious/4eda9cb75909b44e3ad30c9b5f6114b4 to your computer and use it in GitHub Desktop.
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)
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