This relates to an AngularJS application, originally built using yo angular-fullstack
with JS scripting (not ts). Functionally fine, but hitting performance UX issues.
My production deployment is to AWS ElasticBeanstalk nano instances, which probably isn't helping but I get the impression from reading up that my {app|polyfill|vendor}bundles are too big.
Homework done - biblio and webpack.config.plugins at end.
Even with all of the above plus 'lessons learned' from wiser souls than me (see biblio) included in my project, I'm still seeing 'big' warnings from webpack
and large, whole-package bundles in the webpack-bundle-analyzer
output:
polyfills.66cd88606235a4586eb1.js.gz 25.8 kB [emitted]
app.66cd88606235a4586eb1.js.gz 48.8 kB [emitted]
vendor.66cd88606235a4586eb1.js.gz 319 kB [emitted] [big]
../client/index.html 4.77 kB [emitted]
I don't think my app is that complicated. 10-ish components on 4 views, one chart (angular-chart.js).
Here are my questions:
- various modules appear to be bundled whole (e.g. angular 1.23MB, lodash 528KB, ...) For example, I've changed all of my own imports to specific lodash functions/modules, but the overall lodash library is still being bundled. Does that mean that one of my dependencies (or one nested further down is pulling it in, or am I missing something?
- I think I can change my
import module from 'angular';
statements to something more specific likeimport ... from '@angluar/core';
but all the documentation seems to imply that I'd have to upgrade the whole app to Angular5 to do that - am I missing something? (Said another way, I can't find beginner-friendly documentation on angular2 '@angular/core'.) - the
angular-cli
seems to be for newng init
ed projects, so I think it's production shrinking and tree-shaking features aren't available to me unless I upgrade/restructure my project - is that correct? - are the bundles that webpack injects into index.html the gzipped ones? Not sure when/how they get used (if at all).
- I'm configuring and invoking
webpack
fromgulp
- are all of the plugins I'm using (see list above) equivalent to the-p
CLI option? ...or do I need to do more? - Help! What else do I need to look at or do to reduce bundle size? Do I have to go delving in
node_modules/**
to find out what is sucking in whole packages? What am I missing?
TIA
Biblio
- Angular2 CLI huge vendor bundle: how to improve size for prod? - from which I learned about not importing whole modules when I only need a bit of it (spin-off question above)
- How to use babel loader on node_modules in webpack for ES6+? - from which I learned about setting up a raft of webpack plugins to reduce, organise and compress my bundles (spin-off question above)
- https://hackernoon.com/optimising-your-application-bundle-size-with-webpack-e85b00bab579 - from which I got confirmation from Google that my app is slow because the bundles are big and some more webpack config hints
- https://hackernoon.com/reduce-webpack-bundle-size-for-production-880bb6b2c72f - followed all the steps, but it didn't seem to make any different to my bundle sizes
- https://github.com/mgechev/angular-performance-checklist#introduction - picked as much as I could out of this without going to the 'upgrade to 5' areas.
webpack
My webpack config for production build currently includes:
- config.devtool='source-map'
- DefinePlugin (NODE_ENV=production)
- NoEmitOnErrorsPlugin
- UglifyJsPlugin with everything turned up to 11
- OccurrenceOrderPlugin
- AggressiveMergingPlugin
- CommonsChunkPlugin
- ModuleConcatenationPlugin
- HashedModuleIdsPlugin