-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
|
@@ -5412,6 +5228,14 @@ module-deps@^6.0.0: | |||
through2 "^2.0.0" | |||
xtend "^4.0.0" | |||
|
|||
mold-source-map@~0.4.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -308,7 +310,6 @@ class TapTargets extends Gatherer { | |||
*/ | |||
afterPass(passContext) { | |||
const expression = `(function() { | |||
const tapTargetsSelector = "${tapTargetsSelector}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.evaluateAsync(`window.location = '${startUrl}'`) |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea code inside template strings' ${...}
are safe
@@ -1,7 +1,7 @@ | |||
{ | |||
"name": "lighthouse", | |||
"version": "6.3.0", | |||
"description": "Lighthouse", | |||
"description": "Automated auditing, performance metrics, and best practices for the web.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -108,10 +108,9 @@ | |||
"@wardpeet/brfs": "2.1.0-0", | |||
"angular": "^1.7.4", | |||
"archiver": "^3.0.0", | |||
"babel-core": "^6.26.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 bye!
package.json
Outdated
"browserify": "^16.2.3", | ||
"browserify-banner": "^1.0.15", | ||
"bundlesize": "^0.18.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what now
:)
build/build-bundle.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does that leave that gets a source map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-lr
and view the map on https://sokra.github.io/source-map-visualization/dist/lightrider/lighthouse-lr-bundle.js
9.60 MB -> 8.94 MB (7%)dist/lighthouse-dt-bundle.js
2.10 MB -> 1.62 MB (23%)