Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
})
)
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 {
export default async function getFormattedSize(code, filename, zipped) {
const message = zipped ?
prettyBytes(await gzipSize(code)) + " (gz)" :
prettyBytes(code.length)
return message
}
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) {
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),
}
}),
)
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" +
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;