-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Integrate bundlesize
and cap main binary size
#14405
Conversation
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.
Two more changes, in addition to the comments below:
- In order to run this during PR checks, you'll need to call
checkBundleSize
afterbuildRuntime
@ line 603. - Were you going to set up CI integration as described in https://github.com/siddharthkp/bundlesize#2-build-status?
package.json
Outdated
@@ -59,6 +59,7 @@ | |||
"body-parser": "1.18.2", | |||
"browserify": "16.1.1", | |||
"browserify-istanbul": "3.0.1", | |||
"bundlesize": "^0.17.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 should be an exact version. Use:
yarn add --dev --exact bundlesize
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.
Done, thanks.
build-system/pr-check.js
Outdated
const args = compiled | ||
? '-f "./dist/v0.js" -s "75 kB"' | ||
: '-f "./dist/amp.js" -s "315 kB"'; | ||
timedExecOrDie(`npx bundlesize ${args}`); |
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.
Based on https://github.com/siddharthkp/bundlesize#cli, shouldn't this be...
timedExecOrDie(`bundlesize ${args}`);
... without the npx
?
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.
That only works if bundlesize
is installed as a global package. Check out npx: https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b
Weird, Travis appears to build Travis:
Local:
|
Weird. Travis runs on Linux VMs. I ran this locally on Linux, and the size is 315 KB.
|
@choumx maybe do a debug Travis build where you print the contents of |
There are actually many differences e.g. how class functions are declared: It's because we have a different browsers target for Babel on Travis: Lines 1100 to 1104 in 970642f
TIL... |
@erwinmombay Any problems if we also use |
@choumx nope. LGTM |
gulpfile.js
Outdated
@@ -797,9 +798,27 @@ function performBuild(watch) { | |||
buildExtensions({bundleOnlyIfListedInFiles: !watch, watch}), | |||
compile(watch), | |||
]); | |||
}).then(() => { | |||
|
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.
Remove this block?
gulpfile.js
Outdated
if (p.status != 0) { | ||
log(cyan('bundlesize: ') + red('The main bundle (amp.js/v0.js) has ' + | ||
'exceeded its size cap.') + ' This is part of a new effort to reduce ' + | ||
'bundle size (see #14392). Please contact @choumx if this blocks you.'); |
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.
Style nit: Standard warning and error formats used elsewhere in this file are:
log(red('ERROR:'), 'Something bad happened while doing', cyan('foo'), 'to', cyan('bar'), '. Talk to @choumx.');
log(yellow('WARNING:'), 'Something not so bad happened while doing', cyan('foo'), 'to', cyan('bar'), '. Talk to @choumx.');
@rsimha Thanks for the quick reviews. |
Looks like this tool needs r/w access to commit statuses in order to enable GitHub PR integration. Unfortunately, if we store See https://github.com/siddharthkp/bundlesize#2-build-status /cc @cramforce |
const size = compiled ? '75.1kB' : '332.3kB'; | ||
const cmd = `npx bundlesize -f "${file}" -s "${size}"`; | ||
log(green('Running ') + cyan(cmd) + green('...\n')); | ||
const p = exec(cmd); |
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 will result in a warning being printed to advertise the tool's GH integration feature. Not sure it's worth trying to silence it.
https://travis-ci.org/ampproject/amphtml/jobs/362305001#L663-L666
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.
siddharthkp/bundlesize#158 I think it's harmless.
Huh, so how can PR integration on Travis work in the first place? |
I think it's possible on repositories that don't use forks for pull requests. See the text in the blue box here: https://docs.travis-ci.com/user/environment-variables/#Defining-encrypted-variables-in-.travis.yml |
Right-o. 😄 Thanks for the link. |
* Add bundlesize dep. * Move config from package.jsoon to CLI. * Use exact version. * Also run in integration shard in PR builds. * Debugging amp.js. * Revert debugging, use same Babel browser target in Travis and local dev. * Move logic from pr-check.js to gulpfile.js. * Raghu's comments.
@choumx I've created siddharthkp/bundlesize#219 to track the feasibility of GH integration for AMP, given that we accept PRs from forks. |
Fixes #14394.
amp.js
on PR builds with max size of 315 KB (current 314.65 KB)v0.js
on push builds with max size of 75 KB (current 74.9 KB)@rsimha @erwinmombay Needs some extra work for GitHub integration: https://github.com/siddharthkp/bundlesize#2-build-status