How to use gzip-size - 10 common examples

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 lukeed / is-offline / builder.js View on Github external
mkdir('dist').then(() => {
	// Copy as is for ESM
	fs.writeFileSync(pkg.module, data);

	// Minify & print gzip-size
	let { code } = minify(data, { toplevel:true });
	console.log(`> gzip size: ${pretty(sizer.sync(code))}`);

	let keys = [];
	// Mutate exports for CJS
	data = data.replace(/export function\s?(.+?)(?=\()/gi, (_, x) => {
		return keys.push(x) && `function ${x}`;
	});
	keys.sort().forEach(key => {
		data += `\nexports.${key} = ${key};`;
	});
	fs.writeFileSync(pkg.main, data + '\n');

	let name = pkg['umd:name'] || pkg.name;

	// Write UMD bundle
	let UMD = minify(`
	(function (global, factory) {
github wfp / ui / scripts / rollup.config.js View on Github external
ongenerate(bundle, details) {
            const gzipSize = gzip.sync(details.code);
            const { bundleSizeThreshold } = packageJson;
            console.log('Total size (gzipped):', gzipSize); // eslint-disable-line no-console
            if (gzipSize > bundleSizeThreshold) {
              throw new RangeError(
                `Exceeded size threshold of ${bundleSizeThreshold} bytes (gzipped)!`
              );
            }
          },
        },
github kaelig / moniteur / lib / jsparser.js View on Github external
}).then((results) => {
      if (Array.isArray(results)) {
        results.forEach((result) => {
          this.scripts.push(result.body)
        })
      }

      // join all JS string
      parsedData.jsString = this.scripts.join('')
      parsedData.size = Buffer.byteLength(parsedData.jsString, 'utf8')
      parsedData.gzippedSize = gzipSize.sync(parsedData.jsString)
      return resolve(parsedData)
    })
      .catch(reason => reject(reason))
github ngnjs / NGN / test / common / integration / 01-size.js View on Github external
test('Distribution File Sizes', function (t) {
  let filepath = require('path').resolve('./test/lib/ngn.min.js')
  let stats = require('fs').statSync(filepath)
  let uncompressedSize = (stats.size / 1000).toFixed(2)

  t.ok(uncompressedSize < 100, 'Uncompressed distributable file is under 100kb (' + (stats.size / 1000) + 'kb).')

  let compressedSize = (gzip.fileSync(filepath, { level: 9 }) / 1000).toFixed(2)
  t.ok(compressedSize < 30, 'Compressed (minified) distributable is under 30kb (' + compressedSize + 'kb)')

  t.end()
})
github sindresorhus / gzip-size-cli / cli.js View on Github external
const [input] = cli.input;

if (!input && process.stdin.isTTY) {
	console.error('Specify a file path');
	process.exit(1);
}

const source = input ? fs.createReadStream(input) : process.stdin;

const options = {};
if (cli.flags.level) {
	options.level = Number(cli.flags.level);
}

source.pipe(gzipSize.stream(options)).on('gzip-size', size => {
	console.log(cli.flags.raw ? size : prettyBytes(size));
});
github kvendrik / jest-lite / scripts / build-readme.js View on Github external
function updateBundleSizes(readmeContents) {
  let newReadmeContents = readmeContents;
  const bundles = getBundleNames();

  for (const bundleFile of bundles) {
    console.info(`Inspecting dist/${bundleFile}`);

    const bundleContents = readFileSync(
      `${rootPath}/dist/${bundleFile}`,
      'utf-8',
    );

    const gzipSizeBytes = gzipSize.sync(bundleContents);
    const gzipSizeKb = bytesToKilobytes(gzipSizeBytes);

    const bundleSize =
      gzipSizeBytes > 1000 ? `${gzipSizeKb}kb` : `${gzipSizeBytes}b`;

    newReadmeContents = newReadmeContents.replace(
      `{{bundleSize['${bundleFile}']}}`,
      bundleSize,
    );
  }

  return newReadmeContents;
}
github mazipan / vue-currency-filter / check-size.js View on Github external
readDirs(path.resolve('./lib-out/'), async (filepath, filename) => {
    try {
      console.log(chalk.greenBright(`> ${filename}: ${bytes(gzipSize.fileSync(filepath))}`))
    } catch (err) {
      console.error(err)
    }
  }, (err) => {
    console.error(err)
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 QubitProducts / rjs-report / lib / rjs-report.js View on Github external
function getStat(root, module) {
  var modulePath = path.resolve(root, module);
  try {
    var stat = fs.statSync(modulePath);
    return {
      size: stat.size,
      gzipped: gzipSize.sync(fs.readFileSync(modulePath).toString())
    };
  } catch (e) {
    return {
      size: 0,
      gzipped: 0
    };
  }
}
github bevacqua / sektor / gulpfile.js View on Github external
function replaceFootprint (needle, relative, done) {
  var file = path.resolve(relative);
  var data = fs.readFileSync(file);
  var size = gzipSize.sync(data);
  var sizeHuman = prettyBytes(size).replace(/\s+/g, '');
  var readmeFile = path.resolve('./README.md');
  var readme = fs.readFileSync(readmeFile, { encoding: 'utf8' });
  var output = readme.replace(needle, '$1' + sizeHuman + '$3');

  fs.writeFile(readmeFile, output, { encoding: 'utf8'}, done);
}

gzip-size

Get the gzipped size of a string or buffer

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis