Optimize bundled size
See original GitHub issueI’m using styled-components, and am really happy with it. Currently I’m trying to get my app’s bundle size down, and styled-components is among one of the bigger packages. When bundled with webpack, it’s 90.6kB minified (just for styled-components, including some webpack overhead).
When compared with the 167kB for a minified bundle containing almost all my other vendor libs:
'date-fns',
'history',
'load-script',
'normalize.css',
'normalizr',
'react',
'react-helmet',
'react-dom',
'react-medium-image-zoom',
'react-redux',
'react-router',
'react-router-dom',
'redux',
'redux-thunk'
styled-components seems fairly heavy.
I still think it’s worth it, but I’m wondering whether there’s any known optimizations specific to styled-components for getting its bundled size down (outside of general stuff like gzipping, SSR, etc., which is of course not a styled-components specific issue). Any thoughts on this? Worth putting on the roadmap for a future version?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top Results From Across the Web
3 ways to reduce webpack bundle size - Jakob Lind
3 ways to reduce webpack bundle size · Easy: Run webpack in production mode · Medium: use an analyzer tool such as webpack-bundle-analyzer...
Read more >6 tips to optimize bundle size - DEV Community
6 tips to optimize bundle size · 1. Avoid libraries global imports · 3. Do not include source maps · 4. Remove replaceable...
Read more >Small Bundles, Fast Pages: What To Do With Too Much ...
This post will explain why bundle size matters and recommend ... Optimising bundle size doesn't end with one housekeeping effort (we wish!)
Read more >Possible ways to reduce your webpack bundle size - Medium
Here are some cool ways you can reduce your webpack bundle size: ... Can reduce the bundle size. How do I do this?...
Read more >Slimming down your bundle size - LogRocket Blog
Conclusion · Consider rewriting libraries that are large in size where you might not need all of its functionalities. · Check to see...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s definitely on the roadmap for v2. We have a new parser which is much smaller and @philpl is currently developing a new babel-plugin which will remove the need of a run time parser completely. You can try is out with
npm install styled-components@next
and https://github.com/styled-components/babel-plugin-styled-components.IIRC Webpack Visualizer is reporting the bundle sizes before any plugin is executed so nothing is minified or deduplicated here. You might checkout https://github.com/th0r/webpack-bundle-analyzer which is a similar tool but more accurate.
As far as I know React isn’t bundled with styled-components so there shouldn’t be any duplicate React code here.