You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
117 is more than 63 and suspiciously close to source file size, so I took debugger and figured out why.
When looking at the ModuleLengths function, it prefers using the length of code compared to renderedLength, however debugger reveals that the code used is the raw, unprocessed by plugins source of the module. renderLength calculated from sourcemap is correct (16 = length of alert("hello");+newline):
code is taken from output bundle modules, and debugger confirms that this is indeed from before all plugins:
There seems to be 2 potential approaches to fix:
The quick and dirty fix is to just use renderedLength (idk if length from code is needed as fallback?)
Other option is to read the actually rendered code from sourcemap and use it instead of bundle.modules[id].code. This is actually something #164 did, but seems like long feedback cycle and some misunderstandings in review got @thoughtspile to abandon it. But as seen by PR, this is the better approach as it also allows gzip and brotli sizes of modules in sourcemap mode (even if those are misleading as gzip + brotli sizes are highly influenced by how much repeating code there is, but the same issue also applies to sourcemap: false mode)
So I created this issue to check if it's better to
just quickly fix it to use renderedLength over code length
Yep it's continuation of #163 (and externally KusStar/vite-bundle-visualizer#8)
Even after 442517c the sizes in the report mismatch with final output, especially when using minifier (eg. terser). Simple test case:
index.js
(size: 117 bytes, no tailing newline)rollup.config.mjs:
rollup output
output/index.js
: (size 63 bytes)rollup-plugin-visualizer output
stats.yml
:117 is more than 63 and suspiciously close to source file size, so I took debugger and figured out why.
When looking at the ModuleLengths function, it prefers using the length of code compared to renderedLength, however debugger reveals that the code used is the raw, unprocessed by plugins source of the module. renderLength calculated from sourcemap is correct (16 = length of
alert("hello");
+newline):code is taken from output bundle modules, and debugger confirms that this is indeed from before all plugins:
There seems to be 2 potential approaches to fix:
The quick and dirty fix is to just use renderedLength (idk if length from code is needed as fallback?)
stats.yml:
(note: in the sourcemap the
"use strict";
and sourceMappingURL are unmapped, so it showing slightly lower value than bundle size is kinda normal)Other option is to read the actually rendered code from sourcemap and use it instead of
bundle.modules[id].code
. This is actually something #164 did, but seems like long feedback cycle and some misunderstandings in review got @thoughtspile to abandon it. But as seen by PR, this is the better approach as it also allows gzip and brotli sizes of modules in sourcemap mode (even if those are misleading as gzip + brotli sizes are highly influenced by how much repeating code there is, but the same issue also applies tosourcemap: false
mode)So I created this issue to check if it's better to
The text was updated successfully, but these errors were encountered: