Initial commit
This commit is contained in:
commit
07c5428f7c
11 changed files with 1815 additions and 0 deletions
51
rollup-plugins/bundle-size.mjs
Normal file
51
rollup-plugins/bundle-size.mjs
Normal file
|
@ -0,0 +1,51 @@
|
|||
import path from "path";
|
||||
import fs from "fs";
|
||||
import chalk from "chalk";
|
||||
|
||||
export default function bundleSize({ file, maxSize = 13 }) {
|
||||
return {
|
||||
name: "rollup-plugin-bundle-size",
|
||||
writeBundle: {
|
||||
secuential: true,
|
||||
order: "post",
|
||||
async handler(options, bundle) {
|
||||
let uncompressedSize = 0;
|
||||
console.log(
|
||||
chalk.green("Filename".padEnd(30, " ") + "\t Size (bytes).")
|
||||
);
|
||||
for (const file in bundle) {
|
||||
const { modules } = bundle[file];
|
||||
for (const moduleName in modules) {
|
||||
const module = modules[moduleName];
|
||||
const name = path.basename(moduleName);
|
||||
uncompressedSize += module.renderedLength;
|
||||
console.log(
|
||||
`${chalk.cyan(name.padEnd(30, " "))}\t ${chalk.cyan(
|
||||
module.renderedLength
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
chalk.green(
|
||||
"Total before compression " +
|
||||
chalk.bold(chalk.green(uncompressedSize))
|
||||
)
|
||||
);
|
||||
|
||||
const asset = path.join(options.dir, file);
|
||||
const { size } = fs.statSync(asset);
|
||||
const percent = parseInt((size / (maxSize * 1024)) * 100, 10);
|
||||
const color =
|
||||
percent < 50 ? chalk.green : percent < 80 ? chalk.yellow : chalk.red;
|
||||
|
||||
console.log(
|
||||
`Created bundle ${chalk.cyan(asset)}: ${chalk.bold(
|
||||
chalk.cyan(size)
|
||||
)} bytes, ${color(percent + "%")} of total game size used.`
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue