misc(build): minify bundles with terser#9605
Conversation
|
Note: the viewer needs additional changes to its build script to emit a map. This only emits a map for LR, the extension, and DT. |
|
got a visual bundle from the previous process of browserify -> babel (ccf966d). as you can see, "unmapped" went up a lot. |
|
the answer is in here somewhere... (diff b/wn dt bundles) https://gist.github.com/connorjclark/c80ca014042950ff0dd15ee23fcb6f42
|
| through2 "^2.0.0" | ||
| xtend "^4.0.0" | ||
|
|
||
| mold-source-map@~0.4.0: |
There was a problem hiding this comment.
this is an interesting package
|
The culprit is the browserify builtins. They don't get processed by the babelify transform - so comments, whitespace, all remain. |
|
Here where we're at: We do browserify -> babel. Bundle is 1.6M. Babel's job is just to reduce the size of the script (via Moving babel into browserify via We could completely remove the line retaining minimization, and just use Terser. This save ~0.4MB. Source maps are perfect in this two-pass compilation. Terser handles input maps better than babel, apparently. I asked @patrickhulce about the utility of "retain lines" in the bundle output. He said it originated from wanting "readable" diffs when rolling to DevTools. I wonder if that is a behavior we should bother keeping? |
yeah that and the moderately improved stack trace is a nice feature of |
covered! https://www.npmjs.com/package/stack-beautifier |
|
I like getting rid of yet another minifier in our deps :) Did we figure out the serving thing, though? My main thing is probably the occasional stepping through LH in devtools and the current formatting does make that actually viable without a source map. |
|
Agreed with Patrick that it's pretty rare I find myself actually doing that, but then again that means what use are source maps? :) |
For devtools / Lightrider, you can attach source maps from a URL, which you would get by checking out the correct sha, building, and starting a local server in But don't forget the viewer - it's trivial to use maps there. |
|
Worth noting: we have no tests that utilize the output of our bundled code (ala how React tests their lib). We might do good to run the smoke tests on the bundled code (#9501 references how). |
paulirish
left a comment
There was a problem hiding this comment.
unfortunately, building the LR bundle now takes ~60 seconds. but there's not much we can do about that.
a few small things, but is good to get a green
| */ | ||
| afterPass(passContext) { | ||
| const expression = `(function() { | ||
| const tapTargetsSelector = "${tapTargetsSelector}"; |
There was a problem hiding this comment.
i looked through the other uses of evalAsync for a similar situation and i think we're good.
only one that caught my eye was L116 of the start-url gatherer
but looking at the minified source, i think we're ok
ya?
in minified land this was that taptarget section:
There was a problem hiding this comment.
yea code inside template strings' ${...} are safe
| "name": "lighthouse", | ||
| "version": "6.3.0", | ||
| "description": "Lighthouse", | ||
| "description": "Automated auditing, performance metrics, and best practices for the web.", |
| "@wardpeet/brfs": "2.1.0-0", | ||
| "angular": "^1.7.4", | ||
| "archiver": "^3.0.0", | ||
| "babel-core": "^6.26.0", |
| "babel-plugin-syntax-object-rest-spread": "^6.13.0", | ||
| "browserify": "^16.2.3", | ||
| "browserify-banner": "^1.0.15", | ||
| "bundlesize": "^0.18.0", |
| assert.ok(!minified.includes('\nrequire='), 'contained unexpected browserify require stub'); | ||
| // Add the banner and modify globals for DevTools if necessary. | ||
| // This will mess up the source map for the first line, but we don't ship | ||
| // the map to DevTools, so that's fine. |
There was a problem hiding this comment.
what does that leave that gets a source map?
There was a problem hiding this comment.
I just removed this comment since we aren't shipping any maps in CDT or LR. I put the default map generation back to false. can set to true whenever we want to get a bundle viz.
Co-authored-by: Brendan Kenny <bckenny@gmail.com>





I encourage reviewers to
yarn build-lrand view the map on https://sokra.github.io/source-map-visualization/dist/lightrider/lighthouse-lr-bundle.js9.60 MB -> 8.94 MB (7%)dist/lighthouse-dt-bundle.js2.10 MB -> 1.62 MB (23%)