Show info about files/packages included with your rollup bundle
94
Create a Rollup build configuration that analyzes bundle sizes and exports the results to a JSON file for tracking purposes.
You need to set up a Rollup build that generates a bundle size report in JSON format. The report should contain information about which packages are included in the bundle and their sizes.
Your build should:
bundle-report.jsonThe JSON report should contain an array of package entries, where each entry has:
package: the name of the package or category (e.g., "lodash", "app", "rollup helpers")size: the size in bytespercentage: the percentage of total bundle sizeThe report should be sorted by size in descending order (largest packages first).
bundle-report.jsonProvides bundle size analysis capabilities for Rollup builds.
Input:
Run node rollup.config.js to verify the configuration is valid JavaScript.
Expected output: No syntax errors.
Input:
npx rollup -cExpected output:
bundle-report.json is createdpackage, size, and percentage fieldssize values are numberspercentage values are numbers between 0 and 100Input:
Read the generated bundle-report.json file.
Expected output:
The Rollup configuration file that sets up the build with size analysis and custom reporting.
import { sum } from 'lodash-es';
const numbers = [1, 2, 3, 4, 5];
const total = sum(numbers);
console.log(`Total: ${total}`);
export { total };{
"name": "bundle-size-reporter",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "rollup -c"
},
"devDependencies": {
"rollup": "^4.0.0",
"rollup-plugin-sizes": "^1.1.0"
},
"dependencies": {
"lodash-es": "^4.17.21"
}
}Install with Tessl CLI
npx tessl i tessl/npm-rollup-plugin-sizesdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10