How to use the gzip-size.sync 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 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 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 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);
}
github angular / angularfire / tools / build.ts View on Github external
async function measure(module: string) {
  const path = dest('bundles', `${module}.umd.js`);
  const file = await readFile(path);
  const gzip = prettySize(gzipSync(file), true);
  const size = prettySize(file.byteLength, true);
  return { size, gzip };
}
github erlanglab / erlangpl / ui / scripts / build.js View on Github external
.map(asset => {
      var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
      var size = gzipSize(fileContents);
      var previousSize = previousSizeMap[removeFileNameHash(asset.name)];
      var difference = getDifferenceLabel(size, previousSize);
      return {
        folder: path.join('build', path.dirname(asset.name)),
        name: path.basename(asset.name),
        size: size,
        sizeLabel: filesize(size) + (difference ? ' (' + difference + ')' : '')
      };
    });
  assets.sort((a, b) => b.size - a.size);
github lingui / js-lingui / scripts / build / plugins / sizes.js View on Github external
ongenerate(bundle, obj) {
      const size = Buffer.byteLength(obj.code)
      const gzipSize = gzip.sync(obj.code)

      options.getSize(size, gzipSize)
    }
  }
github VolcaTech / eth2-app / scripts / build.js View on Github external
.reduce((memo, fileName) => {
      var contents = fs.readFileSync(fileName);
      var key = removeFileNameHash(fileName);
      memo[key] = gzipSize(contents);
      return memo;
    }, {});

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