angular-bazel-example icon indicating copy to clipboard operation
angular-bazel-example copied to clipboard

Rollup bundle is way too big

Open alexeagle opened this issue 8 years ago • 10 comments

$ bazel build src:bundle
$ ls -alH dist/bin/src/bundle.min.js
-r-xr-xr-x 1 alexeagle eng 928105 Jan 19 16:34 dist/bin/src/bundle.min.js

A hello world app should be a lot smaller. First problem is it brings in rxjs from npm (using commonjs)

/cc @robwormald who helped me debug it

alexeagle avatar Jan 20 '18 00:01 alexeagle

Maybe it makes sense to include a simple plugin to resolve to rxjs esm I have something here:

https://github.com/thelgevold/angular-2-samples/blob/master/rollup/resolve-esm.js

thelgevold avatar Jan 20 '18 01:01 thelgevold

This removes the need for the commonjs plugin (for rxjs). Unless you plan to use it for other libraries later...

thelgevold avatar Jan 20 '18 01:01 thelgevold

When I check the produced bundle for my app using the rollup_bundle rule, there were 21 separate definitions of Observable (Observable through Observable$20.) It looks like the library may be included a large number of times.

Potentially related: when I first set up my rollup_bundle target, in the places of my code where I import rxjs/Observable, Rollup complained about not knowing where to find Observable, so it treated it as a global (even though it still defined several local Observable$N local variables inside of the IIFE.) My app wouldn't work until I added node_modules/rxjs/** back into my //:node_modules filegroup.

pshields avatar Jan 20 '18 13:01 pshields

https://github.com/bazelbuild/rules_nodejs/commit/50160838918fb381ad2691d4ddbd62e4eac17bee should fix this issue with rxjs - we should depend on the files built by bazel, not the rxjs distribution.

Misko found today that we are also missing the Angular Build Optimizer in this path, which does things like these /* @__PURE__ */ annotations that tell uglify that some code can be removed, I'll wire that up next.

alexeagle avatar Jan 25 '18 23:01 alexeagle

We built it again today and it's under 350,000 bytes uncompressed. We are in the ballpark. Working on hooking up @angular-devkit/build-optimizer, maybe need @igorminar to help next week.

alexeagle avatar Jan 27 '18 01:01 alexeagle

i tried to serve example on my mac and I think this issue is related, when ibazel run src:devserver i get this

and when ibazel run src:prodserver i get this output

elvisbegovic avatar Jan 29 '18 18:01 elvisbegovic

@istiti I don't see how that's related to this issue?

alexeagle avatar Jan 29 '18 20:01 alexeagle

Isn't that just ibazel waiting for you to make the next source file change? I don't think there's a slow process there

On Mon, Jan 29, 2018 at 12:56 PM Begović [email protected] wrote:

😕 Apologises me if not, i thought long process was due to rollup

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/alexeagle/angular-bazel-example/issues/62#issuecomment-361383413, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC5I1gXkUL3pzCgqdePWleuJ6BDDtACks5tPjBlgaJpZM4RlOgU .

alexeagle avatar Jan 29 '18 21:01 alexeagle

Improved image but still needs work

alexeagle avatar Feb 08 '18 23:02 alexeagle

Not doing more work on this - new rollup_bundle rule does the same thing you would do outside Bazel so it's not a problem in our scope

alexeagle avatar Sep 12 '19 20:09 alexeagle