How to use the gzip-size function in gzip-size

To help you get started, we’ve selected a few gzip-size examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / client / src / scripts / print-bundle-size.js View on Github external
fs.readFile(minPath, (minErr, minBundle) => {
    throwOnError(minErr)

    gzipSize(bundle, (gzipErr, gzipedSize) => {
      throwOnError(gzipErr)

      const output = [
        'UMD bundle size:',
        '────────────────',
        `Minified: ${size(bundle.length)}`,
        `Minified + gzip: ${size(gzipedSize)}`
      ].join('\n')

      console.log(
        boxen(output, {
          padding: 1,
          borderColor: 'yellow',
          align: 'right'
        })
      )
github steelbrain / pundle / packages / pundle-cli / src / pundle.js View on Github external
async function writeFile(context: Context, filePath: string, contents: string | Buffer): Promise {
  await new Promise(function(resolve, reject) {
    mkdirp(path.dirname(filePath), function(err) {
      if (err) {
        reject(err)
      } else resolve()
    })
  })
  await fs.writeFile(filePath, contents)
  const gzipSizeOfFile = await gzipSize(contents)
  log(
    `  Writing '${chalk.blue(path.relative(context.config.rootDirectory, filePath))}' ${chalk.green(
      prettyBytes(contents.length),
    )} (${chalk.red(prettyBytes(gzipSizeOfFile))} gzipped) `,
  )
}
async function logFile(filePath: string, contents: string | Buffer): Promise {
github sebastian-software / preppy / src / getFormattedSize.js View on Github external
export default async function getFormattedSize(code, filename, zipped) {
  const message = zipped ?
    prettyBytes(await gzipSize(code)) + " (gz)" :
    prettyBytes(code.length)

  return message
}
github steelbrain / pundle / packages / pundle-cli / src / pundle.js View on Github external
async function logFile(filePath: string, contents: string | Buffer): Promise {
  const gzipSizeOfFile = await gzipSize(contents)
  log(
    `  ${chalk.blue(filePath)} - ${chalk.green(prettyBytes(contents.length))} (${chalk.red(
      prettyBytes(gzipSizeOfFile),
    )} gzipped) `,
  )
}
async function writeCompiledChunks(context: Context, generated: ChunksGenerated) {
github smooth-code / bundle-analyzer-javascript / packages / core / src / index.js View on Github external
webpackStats.assets.map(async asset => {
      const fullPath = path.join(webpackStats.outputPath, asset.name)
      const buffer = await readFile(fullPath)
      return {
        ...asset,
        gzipSize: await gzipSize(buffer),
        brotliSize: brotliSize.sync(buffer),
      }
    }),
  )
github TrySound / rollup-plugin-size-snapshot / src / index.js View on Github external
const source = rawSource.replace(/\r/g, "");
      const format = outputOptions.format;
      const output = outputOptions.file;
      const shouldTreeshake = format === "es" || format === "esm";

      if (typeof output !== "string") {
        throw Error("output file in rollup options should be specified");
      }
      const outputName = relative(dirname(snapshotPath), output);

      const minified = minify(source).code;
      const treeshakeSize = code =>
        Promise.all([treeshakeWithRollup(code), treeshakeWithWebpack(code)]);

      return Promise.all([
        gzipSize(minified),
        shouldTreeshake
          ? treeshakeSize(source)
          : [{ code: 0, import_statements: 0 }, { code: 0 }]
      ]).then(([gzippedSize, [rollupSize, webpackSize]]) => {
        const sizes: Object = {
          bundled: source.length,
          minified: minified.length,
          gzipped: gzippedSize
        };

        const prettyFormat = format === "es" ? "esm" : format;
        const prettyBundled = formatSize(sizes.bundled);
        const prettyMinified = formatSize(sizes.minified);
        const prettyGzipped = formatSize(sizes.gzipped);
        let infoString =
          "\n" +
github developit / microbundle / src / index.js View on Github external
async function getSizeInfo(code, filename, raw) {
	const gzip = formatSize(
		await gzipSize(code),
		filename,
		'gz',
		raw || code.length < 5000,
	);
	let brotli;
	//wrap brotliSize in try/catch in case brotli is unavailable due to
	//lower node version
	try {
		brotli = formatSize(
			await brotliSize(code),
			filename,
			'br',
			raw || code.length < 5000,
		);
	} catch (e) {
		return gzip;

gzip-size

Get the gzipped size of a string or buffer

MIT
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis