├── .eslintignore ├── .npmignore ├── .npmrc ├── test ├── specimens │ ├── entry.js │ ├── entry2.js │ ├── maths.js │ └── maths2.js ├── test.js └── __snapshots__ │ └── test.js.snap ├── .eslintrc.js ├── .github ├── dependabot.yml └── workflows │ ├── changesets.yml │ └── ci.yml ├── .gitattributes ├── .changeset ├── config.json └── README.md ├── .vscode └── launch.json ├── package.json ├── LICENSE.md ├── .gitignore ├── README.md ├── index.js └── CHANGELOG.md /.eslintignore: -------------------------------------------------------------------------------- 1 | specimens/ 2 | coverage/ 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .* 2 | test/ 3 | coverage/ 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | message="release: %s :tada: :rocket:" 2 | -------------------------------------------------------------------------------- /test/specimens/entry.js: -------------------------------------------------------------------------------- 1 | import { cube } from './maths.js'; 2 | 3 | console.log( cube( 5 ) ); // 125 4 | -------------------------------------------------------------------------------- /test/specimens/entry2.js: -------------------------------------------------------------------------------- 1 | import { cube } from './maths2.js'; 2 | 3 | console.log( cube( 5 ) ); // 125 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends : [ 3 | "@tivac", 4 | ], 5 | 6 | parserOptions : { 7 | ecmaVersion : 2017, 8 | }, 9 | 10 | env : { 11 | node : true, 12 | es6 : true, 13 | jest : true, 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: monthly 7 | time: "13:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: rollup 11 | versions: 12 | - 2.40.0 13 | -------------------------------------------------------------------------------- /test/specimens/maths.js: -------------------------------------------------------------------------------- 1 | // This function isn't used anywhere, so 2 | // Rollup excludes it from the bundle... 3 | export function square ( x ) { 4 | return x * x; 5 | } 6 | 7 | // This function gets included 8 | export function cube ( x ) { 9 | // rewrite this as `square( x ) * x` 10 | // and see what happens! 11 | return x * x * x; 12 | } 13 | -------------------------------------------------------------------------------- /test/specimens/maths2.js: -------------------------------------------------------------------------------- 1 | // This function isn't used anywhere, so 2 | // Rollup excludes it from the bundle... 3 | export function square ( x ) { 4 | return x * x; 5 | } 6 | 7 | // This function gets included 8 | export function cube ( x ) { 9 | // rewrite this as `square( x ) * x` 10 | // and see what happens! 11 | return x * x * x; 12 | } 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # LINE FEED ALL THE THINGS 2 | * text eol=lf 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { "repo": "tivac/rollup-plugin-sizes" } 6 | ], 7 | "commit": false, 8 | "access": "public", 9 | "baseBranch": "main", 10 | "updateInternalDependencies": "patch", 11 | "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { 12 | "updateInternalDependents": "always" 13 | } 14 | } -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node2", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "program": "${workspaceRoot}/test/test.js", 12 | "cwd": "${workspaceRoot}" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-sizes", 3 | "version": "1.1.0", 4 | "description": "Show info about files/packages included with your rollup bundle", 5 | "main": "index.js", 6 | "repository": "tivac/rollup-plugin-sizes", 7 | "bugs": { 8 | "url": "https://github.com/tivac/rollup-plugin-sizes/issues" 9 | }, 10 | "scripts": { 11 | "lint": "eslint .", 12 | "test": "jest", 13 | "release": "changeset publish" 14 | }, 15 | "keywords": [ 16 | "rollup", 17 | "filesizes", 18 | "bundler", 19 | "rollup-plugin" 20 | ], 21 | "author": "Pat Cavit ", 22 | "license": "MIT", 23 | "devDependencies": { 24 | "@changesets/changelog-github": "^0.5.0", 25 | "@changesets/cli": "^2.26.0", 26 | "@tivac/eslint-config": "^2.3.1", 27 | "eslint": "^8.1.0", 28 | "jest": "^28.0.3", 29 | "rollup": "^4.2.0" 30 | }, 31 | "dependencies": { 32 | "filesize": "^9.0.0", 33 | "module-details-from-path": "^1.0.3" 34 | }, 35 | "peerDependencies": { 36 | "rollup": "^2 || ^3 || ^4" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Pat Cavit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/changesets.yml: -------------------------------------------------------------------------------- 1 | name: Changesets 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | concurrency: ${{ github.workflow }}-${{ github.ref }} 9 | 10 | jobs: 11 | release: 12 | name: Release 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout Repo 16 | uses: actions/checkout@v3 17 | with: 18 | # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits 19 | fetch-depth: 0 20 | 21 | - name: Setup Node 22 | uses: actions/setup-node@v3 23 | with: 24 | node-version: 16 25 | cache: 'npm' 26 | 27 | - name: npm install 28 | run: npm ci 29 | 30 | - name: Create Release Pull Request or Publish to npm 31 | id: changesets 32 | uses: changesets/action@v1 33 | with: 34 | # This expects you to have a script called release which does a build for your packages and calls changeset publish 35 | publish: npm run release 36 | env: 37 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 38 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | "use strict"; 3 | 4 | const { rollup } = require("rollup"); 5 | 6 | const plugin = require("../index.js"); 7 | 8 | describe("rollup-plugin-sizes", () => { 9 | let spy; 10 | 11 | beforeEach(() => { 12 | spy = jest.spyOn(global.console, "log"); 13 | 14 | spy.mockImplementation(() => { /* NO-OP */ }); 15 | }); 16 | 17 | it.each([ 18 | [ "single entry", "./test/specimens/entry.js" ], 19 | [ "multi-entry array", [ 20 | "./test/specimens/entry.js", 21 | "./test/specimens/entry2.js", 22 | ]], 23 | [ "multi-entry object", { 24 | entry : "./test/specimens/entry.js", 25 | entry2 : "./test/specimens/entry2.js", 26 | }], 27 | ])("should describe the sizes of a bundle (%s)", async (name, input) => { 28 | const bundle = await rollup({ 29 | input, 30 | 31 | plugins : [ 32 | plugin({ 33 | details : true, 34 | }), 35 | ], 36 | }); 37 | 38 | await bundle.generate({ format : "es" }); 39 | 40 | expect(spy).toHaveBeenCalled(); 41 | expect(spy.mock.calls).toMatchSnapshot(); 42 | }); 43 | }); 44 | 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directories 27 | node_modules 28 | jspm_packages 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | # ========================= 37 | # Operating System Files 38 | # ========================= 39 | 40 | # OSX 41 | # ========================= 42 | 43 | .DS_Store 44 | .AppleDouble 45 | .LSOverride 46 | 47 | # Thumbnails 48 | ._* 49 | 50 | # Files that might appear in the root of a volume 51 | .DocumentRevisions-V100 52 | .fseventsd 53 | .Spotlight-V100 54 | .TemporaryItems 55 | .Trashes 56 | .VolumeIcon.icns 57 | 58 | # Directories potentially created on remote AFP share 59 | .AppleDB 60 | .AppleDesktop 61 | Network Trash Folder 62 | Temporary Items 63 | .apdisk 64 | 65 | # Windows 66 | # ========================= 67 | 68 | # Windows image file caches 69 | Thumbs.db 70 | ehthumbs.db 71 | 72 | # Folder config file 73 | Desktop.ini 74 | 75 | # Recycle Bin used on file shares 76 | $RECYCLE.BIN/ 77 | 78 | # Windows Installer files 79 | *.cab 80 | *.msi 81 | *.msm 82 | *.msp 83 | 84 | # Windows shortcuts 85 | *.lnk 86 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - '**' 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | 18 | - name: Install node 19 | uses: actions/setup-node@v2 20 | with: 21 | node-version: 18 22 | cache: npm 23 | 24 | - name: Install dependencies 25 | run: npm ci 26 | 27 | - name: Lint 28 | run: npm run lint 29 | 30 | test: 31 | name: node@${{ matrix.node_version }} on ${{ matrix.os }} 32 | 33 | runs-on: ${{ matrix.os }} 34 | 35 | strategy: 36 | matrix: 37 | node_version: [ 16, 18, 20 ] 38 | os: [ ubuntu-latest, windows-latest, macos-latest ] 39 | 40 | steps: 41 | - uses: actions/checkout@v2 42 | 43 | - name: Install node@${{ matrix.node_version }} 44 | uses: actions/setup-node@v2 45 | with: 46 | node-version: ${{ matrix.node_version }} 47 | cache: npm 48 | 49 | - name: npm install 50 | run: npm ci 51 | 52 | - name: Test 53 | run: npm test -- --ci --verbose 54 | 55 | # Run codecov after all builds, and only on a single environment 56 | - name: Gather Coverage 57 | if: matrix.os == 'ubuntu-latest' && matrix.node_version == '18' 58 | run: npm test -- --ci --coverage 59 | 60 | - name: Upload Coverage 61 | uses: codecov/codecov-action@v1 62 | if: matrix.os == 'ubuntu-latest' && matrix.node_version == '18' 63 | with: 64 | token: ${{secrets.CODECOV_TOKEN}} 65 | file: ./coverage/coverage-final.json 66 | 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | rollup-plugin-sizes [![NPM Version](https://img.shields.io/npm/v/rollup-plugin-sizes.svg)](https://www.npmjs.com/package/rollup-plugin-sizes) [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Ftivac%2Frollup-plugin-sizes%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/tivac/rollup-plugin-sizes/goto?ref=main) 2 | =========== 3 |

4 | 5 | 6 | 7 | 8 |

9 | 10 | Simple analysis on rollup bundling, helping you to spot libaries bloating up your bundles. 11 | 12 | ``` 13 | /src/index.js: 14 | codemirror - 446.92 KB (35.94%) 15 | remarkable - 193.72 KB (15.58%) 16 | app - 95.87 KB (7.71%) 17 | autolinker - 81.64 KB (6.57%) 18 | lodash.filter - 62.77 KB (5.05%) 19 | ... 20 | ``` 21 | 22 | or with way more details! 23 | 24 | ``` 25 | /src/index.js: 26 | codemirror - 446.92 KB (35.94%) 27 | lib\codemirror.js - 347.8 KB (77.82%) 28 | mode\javascript\javascript.js - 27.78 KB (6.22%) 29 | mode\markdown\markdown.js - 25.54 KB (5.72%) 30 | mode\meta.js - 14.44 KB (3.23%) 31 | mode\xml\xml.js - 12.52 KB (2.80%) 32 | addon\edit\closebrackets.js - 7.04 KB (1.58%) 33 | addon\edit\matchbrackets.js - 5.39 KB (1.21%) 34 | addon\comment\continuecomment.js - 3.59 KB (0.80%) 35 | addon\selection\active-line.js - 2.82 KB (0.63%) 36 | remarkable - 193.72 KB (15.58%) 37 | lib\common\entities.js - 46.44 KB (23.97%) 38 | lib\rules.js - 10.2 KB (5.26%) 39 | lib\rules_block\list.js - 6.65 KB (3.43%) 40 | lib\ruler.js - 5.44 KB (2.81%) 41 | lib\rules_block\deflist.js - 5.22 KB (2.69%) 42 | ... 43 | ``` 44 | 45 | ## Install 46 | 47 | `$ npm i rollup-plugin-sizes -D` 48 | 49 | ## Usage 50 | 51 | Add to your rollup build as the last plugin via JS API or Config file. 52 | 53 | ### JS API 54 | 55 | ```js 56 | var rollup = require("rollup"), 57 | 58 | buble = require("rollup-plugin-buble"), 59 | sizes = require("rollup-plugin-sizes"); 60 | 61 | rollup.rollup({ 62 | entry : "src/main.js", 63 | plugins : [ 64 | buble(), 65 | sizes() 66 | ] 67 | }).then(function(bundle) { 68 | ... 69 | }); 70 | ``` 71 | 72 | ## Config file 73 | 74 | ```js 75 | import buble from 'rollup-plugin-buble'; 76 | import sizes from 'rollup-plugin-sizes'; 77 | 78 | export default { 79 | ... 80 | plugins : [ 81 | buble(), 82 | sizes() 83 | ] 84 | }; 85 | ``` 86 | 87 | ## Options 88 | 89 | `details` - Set to true to enable file-by-file breakdowns of space usage. 90 | 91 | `report` - Customize reporting. See [source code](index.js) for the default reporter. 92 | -------------------------------------------------------------------------------- /test/__snapshots__/test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`rollup-plugin-sizes should describe the sizes of a bundle (multi-entry array) 1`] = ` 4 | Array [ 5 | Array [ 6 | "%s:", 7 | "./test/specimens/entry.js", 8 | ], 9 | Array [ 10 | "%s - %s (%s%%)", 11 | "app", 12 | "345 B", 13 | "100.00", 14 | ], 15 | Array [ 16 | " %s - %s (%s%%)", 17 | "maths.js", 18 | "276 B", 19 | "80.00", 20 | ], 21 | Array [ 22 | " %s - %s (%s%%)", 23 | "entry.js", 24 | "69 B", 25 | "20.00", 26 | ], 27 | Array [ 28 | "%s:", 29 | "./test/specimens/entry.js", 30 | ], 31 | Array [ 32 | "%s - %s (%s%%)", 33 | "app", 34 | "345 B", 35 | "100.00", 36 | ], 37 | Array [ 38 | " %s - %s (%s%%)", 39 | "maths.js", 40 | "276 B", 41 | "80.00", 42 | ], 43 | Array [ 44 | " %s - %s (%s%%)", 45 | "entry.js", 46 | "69 B", 47 | "20.00", 48 | ], 49 | Array [ 50 | "%s:", 51 | "./test/specimens/entry2.js", 52 | ], 53 | Array [ 54 | "%s - %s (%s%%)", 55 | "app", 56 | "346 B", 57 | "100.00", 58 | ], 59 | Array [ 60 | " %s - %s (%s%%)", 61 | "maths2.js", 62 | "276 B", 63 | "79.77", 64 | ], 65 | Array [ 66 | " %s - %s (%s%%)", 67 | "entry2.js", 68 | "70 B", 69 | "20.23", 70 | ], 71 | ] 72 | `; 73 | 74 | exports[`rollup-plugin-sizes should describe the sizes of a bundle (multi-entry object) 1`] = ` 75 | Array [ 76 | Array [ 77 | "%s:", 78 | "./test/specimens/entry.js", 79 | ], 80 | Array [ 81 | "%s - %s (%s%%)", 82 | "app", 83 | "345 B", 84 | "100.00", 85 | ], 86 | Array [ 87 | " %s - %s (%s%%)", 88 | "maths.js", 89 | "276 B", 90 | "80.00", 91 | ], 92 | Array [ 93 | " %s - %s (%s%%)", 94 | "entry.js", 95 | "69 B", 96 | "20.00", 97 | ], 98 | Array [ 99 | "%s:", 100 | "./test/specimens/entry.js", 101 | ], 102 | Array [ 103 | "%s - %s (%s%%)", 104 | "app", 105 | "345 B", 106 | "100.00", 107 | ], 108 | Array [ 109 | " %s - %s (%s%%)", 110 | "maths.js", 111 | "276 B", 112 | "80.00", 113 | ], 114 | Array [ 115 | " %s - %s (%s%%)", 116 | "entry.js", 117 | "69 B", 118 | "20.00", 119 | ], 120 | Array [ 121 | "%s:", 122 | "./test/specimens/entry2.js", 123 | ], 124 | Array [ 125 | "%s - %s (%s%%)", 126 | "app", 127 | "346 B", 128 | "100.00", 129 | ], 130 | Array [ 131 | " %s - %s (%s%%)", 132 | "maths2.js", 133 | "276 B", 134 | "79.77", 135 | ], 136 | Array [ 137 | " %s - %s (%s%%)", 138 | "entry2.js", 139 | "70 B", 140 | "20.23", 141 | ], 142 | Array [ 143 | "%s:", 144 | "./test/specimens/entry.js", 145 | ], 146 | Array [ 147 | "%s - %s (%s%%)", 148 | "app", 149 | "345 B", 150 | "100.00", 151 | ], 152 | Array [ 153 | " %s - %s (%s%%)", 154 | "maths.js", 155 | "276 B", 156 | "80.00", 157 | ], 158 | Array [ 159 | " %s - %s (%s%%)", 160 | "entry.js", 161 | "69 B", 162 | "20.00", 163 | ], 164 | Array [ 165 | "%s:", 166 | "./test/specimens/entry2.js", 167 | ], 168 | Array [ 169 | "%s - %s (%s%%)", 170 | "app", 171 | "346 B", 172 | "100.00", 173 | ], 174 | Array [ 175 | " %s - %s (%s%%)", 176 | "maths2.js", 177 | "276 B", 178 | "79.77", 179 | ], 180 | Array [ 181 | " %s - %s (%s%%)", 182 | "entry2.js", 183 | "70 B", 184 | "20.23", 185 | ], 186 | ] 187 | `; 188 | 189 | exports[`rollup-plugin-sizes should describe the sizes of a bundle (single entry) 1`] = ` 190 | Array [ 191 | Array [ 192 | "%s:", 193 | "./test/specimens/entry.js", 194 | ], 195 | Array [ 196 | "%s - %s (%s%%)", 197 | "app", 198 | "345 B", 199 | "100.00", 200 | ], 201 | Array [ 202 | " %s - %s (%s%%)", 203 | "maths.js", 204 | "276 B", 205 | "80.00", 206 | ], 207 | Array [ 208 | " %s - %s (%s%%)", 209 | "entry.js", 210 | "69 B", 211 | "20.00", 212 | ], 213 | ] 214 | `; 215 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | "use strict"; 3 | 4 | const path = require("path"); 5 | 6 | const parse = require("module-details-from-path"); 7 | const filesize = require("filesize"); 8 | 9 | function defaultReport(details) { 10 | const args = Object.assign({}, details); 11 | 12 | // Sort 13 | args.totals.sort((a, b) => b.size - a.size); 14 | console.log("%s:", args.input); 15 | 16 | args.totals.forEach((item) => { 17 | const itemSize = item.size || 0; 18 | 19 | console.log( 20 | "%s - %s (%s%%)", 21 | item.name, 22 | filesize(itemSize), 23 | ((itemSize / args.total) * 100).toFixed(2) 24 | ); 25 | 26 | if(args.options.details) { 27 | args.data[item.name] 28 | .sort((a, b) => b.size - a.size) 29 | .forEach((file) => console.log( 30 | "\t%s - %s (%s%%)", 31 | file.path, 32 | filesize(file.size || 0), 33 | ((file.size / itemSize) * 100).toFixed(2) 34 | )); 35 | } 36 | }); 37 | } 38 | 39 | module.exports = (options) => { 40 | let input; 41 | let bases; 42 | 43 | if(!options) { 44 | options = false; 45 | } 46 | 47 | const report = (options && options.report) || defaultReport; 48 | 49 | return { 50 | name : "rollup-plugin-sizes", 51 | 52 | // Grab some needed bits out of the options 53 | options : (config) => { 54 | const { input : original } = config; 55 | 56 | if(Array.isArray(original)) { 57 | input = original; 58 | } else if(typeof original === "object") { 59 | input = Object.values(original); 60 | } else if(typeof original === "undefined") { 61 | input = []; 62 | } else { 63 | input = [ original ]; 64 | } 65 | 66 | bases = input.map((file) => path.dirname(file)); 67 | }, 68 | 69 | // Spit out stats during bundle generation 70 | generateBundle : (_, bundles) => { 71 | Object.values(bundles).forEach((bundle, idx) => { 72 | if(!bundle.modules) { 73 | return; 74 | } 75 | 76 | const base = bases[idx] || ""; 77 | 78 | let total = 0; 79 | const data = {}; 80 | const totals = []; 81 | const ids = Object.keys(bundle.modules); 82 | 83 | ids.forEach((id) => { 84 | const module = bundle.modules[id]; 85 | let parsed; 86 | 87 | // Handle rollup-injected helpers 88 | if(id.indexOf("\u0000") === 0) { 89 | parsed = { 90 | name : "rollup helpers", 91 | basedir : "", 92 | path : id.replace("\u0000", ""), 93 | }; 94 | } else { 95 | parsed = parse(id); 96 | 97 | if(!parsed) { 98 | parsed = { 99 | name : "app", 100 | basedir : base, 101 | path : path.relative(base, id), 102 | }; 103 | } 104 | } 105 | 106 | if(!(parsed.name in data)) { 107 | data[parsed.name] = []; 108 | } 109 | 110 | data[parsed.name].push(Object.assign(parsed, { size : module.originalLength })); 111 | }); 112 | 113 | // Sum all files in each chunk 114 | Object.entries(data).forEach(([ name, files ]) => { 115 | const sum = files.reduce((out, { size }) => out + size, 0); 116 | 117 | total += sum; 118 | 119 | totals.push({ 120 | name, 121 | size : sum, 122 | }); 123 | }); 124 | 125 | report({ 126 | input : input[idx] || bundle.fileName, 127 | data, 128 | totals, 129 | total, 130 | options, 131 | }); 132 | }); 133 | }, 134 | }; 135 | }; 136 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.5 2 | 3 | ## 1.1.0 4 | 5 | ### Minor Changes 6 | 7 | - [#202](https://github.com/tivac/rollup-plugin-sizes/pull/202) [`a9db23c`](https://github.com/tivac/rollup-plugin-sizes/commit/a9db23c525cf9fab79eae8d16d11dcdb41c0bd50) Thanks [@dreuter](https://github.com/dreuter)! - Made this plugin compatible with `vite` 8 | 9 | ## 1.0.6 10 | 11 | ### Patch Changes 12 | 13 | - [#178](https://github.com/tivac/rollup-plugin-sizes/pull/178) [`2ba0ba1`](https://github.com/tivac/rollup-plugin-sizes/commit/2ba0ba13b0b3cb605e5954ad82de220c68b419c2) Thanks [@tbouffard](https://github.com/tbouffard)! - feat: add rollup@4 support 14 | 15 | ### Patch Changes 16 | 17 | - [#143](https://github.com/tivac/rollup-plugin-sizes/pull/143) [`79ceac1`](https://github.com/tivac/rollup-plugin-sizes/commit/79ceac1a68c0b2a1372525983dac3f9f3b02fafc) Thanks [@tivac](https://github.com/tivac)! - Add support for `rollup@3` 18 | 19 | ## [1.0.4](https://github.com/tivac/rollup-plugin-sizes/compare/v1.0.3...v1.0.4) (2021-02-26) 20 | 21 | ### Bug Fixes 22 | 23 | - don't crash when module doesn't map to an input ([#76](https://github.com/tivac/rollup-plugin-sizes/issues/76)) ([881eada](https://github.com/tivac/rollup-plugin-sizes/commit/881eada617a03765dfd0d7e5413b3b364b12650d)) 24 | 25 | ## [1.0.3](https://github.com/tivac/rollup-plugin-sizes/compare/v1.0.2...v1.0.3) (2020-07-22) 26 | 27 | ## [1.0.2](https://github.com/tivac/rollup-plugin-sizes/compare/v1.0.1...v1.0.2) (2020-03-18) 28 | 29 | ### Bug Fixes 30 | 31 | - missing module property doesn't explode [#40](https://github.com/tivac/rollup-plugin-sizes/issues/40) ([#41](https://github.com/tivac/rollup-plugin-sizes/issues/41)) ([6e16c49](https://github.com/tivac/rollup-plugin-sizes/commit/6e16c4980745e1567eea133a65d343af14d68d46)) 32 | 33 | ## [1.0.1](https://github.com/tivac/rollup-plugin-sizes/compare/v1.0.0...v1.0.1) (2019-12-07) 34 | 35 | # [1.0.0](https://github.com/tivac/rollup-plugin-sizes/compare/v0.5.1...v1.0.0) (2019-12-07) 36 | 37 | ### Features 38 | 39 | - better multi-bundle support ([78be22b](https://github.com/tivac/rollup-plugin-sizes/commit/78be22b36dae28f42f9fe0433746aa43c8bf678d)) 40 | - update deprecated ongenerate hook to generateBundle ([#15](https://github.com/tivac/rollup-plugin-sizes/issues/15)) ([f2df7a8](https://github.com/tivac/rollup-plugin-sizes/commit/f2df7a8fec379a839c9ec0762be548a3ed438449)) 41 | 42 | ### BREAKING CHANGES 43 | 44 | - rollup@1 is required to use the generateBundle hook 45 | 46 | ## [0.5.1](https://github.com/tivac/rollup-plugin-sizes/compare/v0.5.0...v0.5.1) (2019-02-25) 47 | 48 | # [0.5.0](https://github.com/tivac/rollup-plugin-sizes/compare/v0.4.2...v0.5.0) (2019-02-25) 49 | 50 | ### Bug Fixes 51 | 52 | - compatiblity with rollup 1.x ([#11](https://github.com/tivac/rollup-plugin-sizes/issues/11)) ([3dbb2fe](https://github.com/tivac/rollup-plugin-sizes/commit/3dbb2fe5a9ffc25aca3b2af564b58e8122c5ea10)) 53 | 54 | ## [0.4.2](https://github.com/tivac/rollup-plugin-sizes/compare/v0.4.1...v0.4.2) (2017-11-01) 55 | 56 | ## [0.4.1](https://github.com/tivac/rollup-plugin-sizes/compare/v0.4.0...v0.4.1) (2017-11-01) 57 | 58 | ### Bug Fixes 59 | 60 | - Replace 'entry' with 'input' ([#5](https://github.com/tivac/rollup-plugin-sizes/issues/5)) ([8ae4f50](https://github.com/tivac/rollup-plugin-sizes/commit/8ae4f50c1a118eb6e28e3463969356200de0383c)) 61 | 62 | # [0.4.0](https://github.com/tivac/rollup-plugin-sizes/compare/v0.3.0...v0.4.0) (2017-06-17) 63 | 64 | # [0.3.0](https://github.com/tivac/rollup-plugin-sizes/compare/v0.2.3...v0.3.0) (2017-06-17) 65 | 66 | ### Bug Fixes 67 | 68 | - disable eslint for now ([9a4f0e4](https://github.com/tivac/rollup-plugin-sizes/commit/9a4f0e4bdd4a88f63d1445147bb649c79a844976)) 69 | - reflect latest commonjs changes, more accurate totals ([793565f](https://github.com/tivac/rollup-plugin-sizes/commit/793565f84f842fdd868adc49295000dfe55454e8)), closes [#2](https://github.com/tivac/rollup-plugin-sizes/issues/2) 70 | - remove object destructuring ([03966c1](https://github.com/tivac/rollup-plugin-sizes/commit/03966c1f52ba7ad3aa1b73a15933dd14c1fb0ded)) 71 | 72 | ### Features 73 | 74 | - Custom reporter support ([#3](https://github.com/tivac/rollup-plugin-sizes/issues/3)) ([7505a7e](https://github.com/tivac/rollup-plugin-sizes/commit/7505a7ee36a3a3bcd0ceee3c1563e0803e7da9ee)) 75 | 76 | ## [0.2.3](https://github.com/tivac/rollup-plugin-sizes/compare/v0.2.2...v0.2.3) (2016-08-16) 77 | 78 | ## [0.2.2](https://github.com/tivac/rollup-plugin-sizes/compare/v0.2.1...v0.2.2) (2016-08-16) 79 | 80 | ## [0.2.1](https://github.com/tivac/rollup-plugin-sizes/compare/v0.2.0...v0.2.1) (2016-08-16) 81 | 82 | # [0.2.0](https://github.com/tivac/rollup-plugin-sizes/compare/v0.1.0...v0.2.0) (2016-08-16) 83 | 84 | # 0.1.0 (2016-08-16) 85 | --------------------------------------------------------------------------------