UNPKG

npm-install-size

Version:

Check the install size of any NPM package before installing it.

15 lines (14 loc) 524 B
import { readFile } from 'fs/promises'; import * as terser from 'terser'; import zlib from 'zlib'; export async function minifyAndGzipFile(filePath) { const code = await readFile(filePath, 'utf8'); const minified = await terser.minify(code); if (!minified.code) throw new Error('Minification failed'); const minifiedBuffer = Buffer.from(minified.code, 'utf8'); const gzipped = zlib.gzipSync(minifiedBuffer); return { minifiedSize: minifiedBuffer.length, gzippedSize: gzipped.length }; }