angular / closure-demo

MIT License
115 stars 27 forks source link

Zone.js in closure bundle (reduced bundle) & Bazel express server build #13

Closed gregmagolan closed 6 years ago

gregmagolan commented 6 years ago

A way to bring zone.js into the bundle built by closure. This takes about 900 bytes off of the final compressed package size.

&

A Bazel built express server as a demonstration.

@alexeagle I had problems serving up the angular-bazel-example Angular app with the same express server as the app is built with "module":"commonjs" so the scripts are not easy to load in the browser. With this repo, the Angular app is nicely bundled into a single bundle.js that loads up easily.

alexeagle commented 6 years ago

oh, I understand now, you're using closure to convert commonjs to hoisted modules. that's an interesting workaround, but I don't think we want to have other people do that right now, it's pretty confusing, and closure is way too slow to be in the development round-trip. @vsavkin does something similar but uses webpack to convert sources to browser-loadable instead of closure compiler. I think the "right" way is https://github.com/bazelbuild/rules_typescript/issues/19

gregmagolan commented 6 years ago

Sure. I can separate the two and move the bazel express build to angular-bazel-example.

I'll check out bazelbuild/rules_typescript#19. If I can bundle/transform the Angular app there without closure so its not commonjs then it can be served up.

gregmagolan commented 6 years ago

"Also at some point, loading zone twice on the page didn't work, and it should be possible to closure-compile two different apps and bootstrap both on the same page"

That's interesting. I hadn't thought of that. Could bundle a polyfills.js in that case with closure and have zone in there as well as any other polyfills instead of loading zone.min.js directly.

alexeagle commented 6 years ago

In theory, zone.js should be stable and very CDN-cacheable (same with other common polyfills) so you get less benefit bundling these together (if any of them changes, the whole polyfill needs to be downloaded again). But I'm not the expert on that :) maybe we can just make zone.min.js smaller (optimize it with closure compiler before publishing?)

Anyway I suspect this isn't the low-hanging-fruit of size reductions.

On Thu, Aug 17, 2017 at 11:45 AM Greg Magolan notifications@github.com wrote:

"Also at some point, loading zone twice on the page didn't work, and it should be possible to closure-compile two different apps and bootstrap both on the same page"

That's interesting. I hadn't thought of that. Could bundle a polyfill.js in that case and have zone in there as well as any other polyfills instead of loading zone.min.js directly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/closure-demo/pull/13#issuecomment-323160075, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC5I4WxxSkfpHCVNB8laNMgs4i8dXW-ks5sZIo5gaJpZM4O57G6 .