Skip to content
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

Bundle flutter.js via esbuild #47573

Merged
merged 7 commits into from
Nov 3, 2023

Conversation

eyebrowsoffire
Copy link
Contributor

  • Roll esbuild as a CIPD package along with the browser roller. I renamed browser_lock/browser_roller etc to package_lock and package_roller since it will handle more than just browsers now.
  • Download the esbuild CIPD package via DEPS.
  • Have a build rule for running esbuild on some JavaScript or TypeScript
  • Bundle and minify flutter.js using esbuild.
  • Include in flutter_web_sdk the original flutter.js source, the minified flutter.js, and a sourcemap file to map between thnm.
  • Also slightly changed the structure to put the flutter.js stuff in flutter_web_sdk/flutter_js instead of just at the root level of flutter_web_sdk. This should be fine because I haven't merged the change that has the flutter tool consume this yet.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie or stuartmorgan on the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Nov 1, 2023
@eyebrowsoffire
Copy link
Contributor Author

Btw, testing this in presubmit here: flutter/flutter#137113

# flutter.js bundled source and sourcemap
sources += [
"$root_out_dir/flutter_web_sdk/flutter_js/flutter.js",
"$root_out_dir/flutter_web_sdk/flutter_js/flutter.js.map",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should publish both optimized and raw flutter.js so that it is possible to troubleshoot issues in debug and profile builds. In fact, until the size of flutter.js is more than a blip, I wouldn't bother minifying, just strip the TypeScript type annotations. Alternatively, if we could roll esbuild all the way to the Flutter SDK (how big is the binary?), and then provide optimization/minification options in the Flutter Tool. This way they engine build of flutter.js can be distributed in original source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually are publishing both with this PR now! We ship the minified version, the original source, and the sourcemaps that map between them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! about how big it is without minification?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now uncompressed it's 14kb before minification, 4kb after, so not terribly significant. The main reason to be bundling is to merge multiple files into one so that we don't have a complex waterfall with multiple roundtrips. Obviously right now there is just a single file, but I'm trying to prepare to modularize it into separate .ts files. Since we have sourcemaps and are shipping the original source, I don't really see a downside to actually minifying it since we're already bundling though.

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if LGT @ditman

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments, but let's go!


esbuild("flutter_js_bundle") {
entry_point = "$root_out_dir/flutter_web_sdk/flutter_js/src/flutter.js"
output_bundle = "$root_out_dir/flutter_web_sdk/flutter_js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want this to be $root_out_dir/flutter_web_sdk/flutter_js/dist or similar? (this might be problematic for the sourcemaps maybe?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that will end up with the sourcemaps mapping to ../src/flutter.js, which I don't think is going to work well when served via http. I'm not exactly sure how to around that issue with a dist folder to be honest.

Comment on lines 31 to 33
"--bundle",
"--minify",
"--sourcemap",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these 3 args be passed in from the invoker? That way the esbuild action is more generic, and the operations that are performed on the source are defined close to where the actual flutter.js build target is defined?

esbuild("flutter_js_bundle") {
entry_point = "$root_out_dir/flutter_web_sdk/flutter_js/src/flutter.js"
output_bundle = "$root_out_dir/flutter_web_sdk/flutter_js"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(add the esbuild args here?)

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 3, 2023
@auto-submit auto-submit bot merged commit 43db22e into flutter:main Nov 3, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 3, 2023
…137872)

flutter/engine@035740c...ec20731

2023-11-03 skia-flutter-autoroll@skia.org Roll Dart SDK from 529fcd5bdffc to c52fb4fe2d86 (1 revision) (flutter/engine#47668)
2023-11-03 jacksongardner@google.com Bundle flutter.js via esbuild (flutter/engine#47573)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Jun 4, 2024
PR #47573 renamed the version-lock file from `browser_lock.yaml` to `package_lock.yaml`. This PR adjusts sources to changes.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants