-
Notifications
You must be signed in to change notification settings - Fork 12k
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
tree-shaking #6676
Comments
The very same goes for Angular Material. Once upon a time.. it worked.. I just got the Components that I imported but now it's the whole shabang lurking around the vendor.ts.. sadly I do not rly know when it stoped working. Demo App to try out: https://github.com/bboehm86/mat-chunk-test |
Can confirm the same for Lodash. Can't tell if it worked on earlier versions, since I used to use full import on lodash.
I still get the whole lodash lib loaded in.. @angular/cli: 1.1.0 |
@daniele-zurico @dojchek @bboehm86 I think your issue is duplicate of this: The Angular CLI team said it's webpack issue therefore it should be reported there and track there. (webpack/webpack#2899). The sad thing is that issue in webpack is open for 10 months now and doesn't seem to go anywhere. These led me to believe that maybe CLI should be discourage for use in production, as it clearly doesn't do it's job and making really big bundles. I'm also struggling because of that issue as it's impacting performance a lot. If you are using Angular lazy loading ( loadChildren in router) it's even worse because chunks are really big (1 mb each piece of really small modules), that you get 9 Mb bundle of 5 mb vendor and 4 mb of modules (so sum is 9). Without lazy loading it's little better because you have 5-6mb depending on code base, but still quite not what I expect as I'm using really only small part of RxJS and angular material. |
@Delagen as far I remember problem was with UglifyJS. Is that included in your webpack config? See relevant threads: |
@galuszkak This diagrams for minified code with uglify, tried to use Closure, but no success. Uglify works |
I think in webpack config does not added 'module' field to resolve section, this is why modules resolved via main field and es6 modules does not used |
Ps may be it left for performance? With real tree shaking my project build up to 20!!! minutes with webpack. May be with rollup will be faster |
Webpack defaults to resolving So I'm trying to test this, and to do so I did
I use Running this script on a brand new project, and zooming in to Then on Now there are five operators, the same as before plus This to me seems like the tree shaking available in webpack is working correctly - only the operator I asked for was added. I cannot speak for Material, but they seem to have an issue opened for how their packaging format is amenable to tree shaking: angular/components#4137. For the other example provided here (rxjs, lodash), I'd say that your app might not be using the other operators but a third party library is, and so they get included. |
@filipesilva RXJS fine |
@Delagen those are the correct files for |
@filipesilva I know |
What is your pipeline? |
@filipesilva I manually build my application using |
@filipesilva what you mean with that: |
I will still argue that this issue is dupe of: #2901 and @filipesilva said it's related to and it's watching it: webpack/webpack#2899 But it's about year and that issue is still there. Webpack people are saying that this is mostly issue with UglifyJS, so I'm quite confused because I'm experiencing this issue also for some time. |
@Delagen then that massively depends on your webpack configuration. Internally the CLI uses @daniele-zurico I mean that, if your third party libraries use RxJs or Lodash, it will of course be included in the final build even if your app does not use it directly. |
@filipesilva also if lodash is not used at all in my code? |
@daniele-zurico |
@filipesilva I use generic config with uglify. It seems some plugin disable tree shaking at all. |
@Delagen it really depends on a lot of things. If you could provide me with your config I can run some benchmarks and see if something could be used in the in CLI that we aren't using already. |
unsubscribe me please to many emails thank you
…On Mon, Jul 17, 2017 at 11:22 AM, Filipe Silva ***@***.***> wrote:
@Delagen <https://github.com/delagen> it really depends on a lot of
things. If you could provide me with your config I can run some benchmarks
and see if something could be used in the in CLI that we aren't using
already.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6676 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AIBfew3Hr2yXHACBXL2AspK3pbMfvcYRks5sO5g8gaJpZM4N5wlw>
.
|
@bossysmile11 I cannot unsubscribe you myself, but you can click on this button on the side of the issue in github: |
@filipesilva I cannot provide config, cause it generated with private library at runtime. Simply used loaderoptions plugin with minimize and disable debug options, uglifyjs. Used awesome-typescript-loader as typescript with module Es2015 setting, with ts 2.4.1 ESNext. I try to make demo repo for this. |
Thank you for taking the time to do it @Delagen 👍 |
@filipesilva Yes. It's causes that you ignored source-maps in node_modules, so users saw as error.
Created sample project. Difference is about 1K |
Sorry guys but at that point I got lost....starting from my original issue...do you think that everything is working as expected? I need to do something? or is not doing tree shacking properly? |
is that available in 1.2.1? or we need to wait the next release? |
Scope hoisting is available in 1.3.0-beta.1. Both should be available in 1.3.0 final. |
and what about my actual command to build in production mode? |
I'm not sure what you mean, can you rephrase that? |
To build in production mode i'm using this command: |
Just doing |
|
but is the opposite ... I was expecting that but: |
The greyed out (bigger) number is the content size (after being unzipped), while the black number is the size of the response (what was transferred) itself. Due to gzip, the response is smaller than the content. In You used some server to server the result of |
@filipesilva the optimizer you referenced seems a great feature.
Is this then not a problem of webpack but of the angular compiler, that leaves function calls not marked as pure when creating the factories?
I never used Will this be addressed with the optimizer you mentioned? |
@ianchi for information on Angular Material tree shaking, check out angular/components#4137. |
@filipesilva I've just tried the new RC of the cli, which includes the optimizer. |
@ianchi that's great news! Let me know if you experience any problems with it. |
I need to do more testing, but so far, it's not working if you
|
Yeah that seems to be missing. You can get it from |
Tree shaking is working much better with this plugin.
I'm not sure if I get it quite right, but it seems that the definition of I don't know where do Decorators get transformed to this chained construction. I guess the Angular Compiler? Another question. Is there any option in the CLI to add html minification of the component's templates? Perhaps in the ejected project I can add the loader to the html chain with raw-loader or is it handled internally in the ngtools/webpack-loader?. It would be nice to have it directly in the CLI. Finally, I wanted to also check using source map explorer, but the generated source map (with -sm option) only shows "*" for all the vendor sources. Any hint to make it work, so it also follows the source files in node_modules?
stats.json also seems to be somehow broken, as I cannot explore it with any tool. |
@ianchi there is no support for html minification in the CLI no. There's a bug with sourcemaps with Unsure what's wrong with As for the Material styles you related, I cannot answer but will ping the appropriate people (@IgorMinar @kara). |
Also, thanks for looking at it so attentively, this is all great feedback! |
Perhaps the problem with styles is that the call to
In constrast, ngFactories are annotated and thus unused ones get removed:
The comma operator construct, must be some kind of Uglify optimization. Going back to HTML minification, are there plans to add it to components' templates? Is there a way I can add it in the ejected webpack? I suspect this must be done inside the ngtools/webpack loader, in between the replacement to require the html template file and the compiling of the string. |
We fiddled with html processing for images a while ago, and couldn't reach a secure approach so left them as is. On an ejected config you can probably edit the loader for html (currently Thinking about it a bit more, I'm not 100% sure that will work with |
is possible to eject as well with --bo command? v1.4.0 |
@daniele-zurico There are no |
Why was this closed? All of the above issues still occur. |
@raysuelzer probably it means "WON'T FIX". |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
@angular/cli: 1.1.1
node: 7.5.0
os: darwin x64
Hello all,
I'm struggling with tree shaking because it looks like that it doesn't work properly.
after running the follow command:
"bundle-report": "ng build --prod --target=production --environment=prod --aot --stats-json && webpack-bundle-analyzer dist/stats.json",
I realised that my vendor is: 2.4 MB and contain stuff that I don't use. RxJs for example take:
But in my code I use like that:
I'm doing something wrong or something wrong is in the tree shaking?
The text was updated successfully, but these errors were encountered: