question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimize bundled size

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
k15acommented, Apr 5, 2017

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.

2reactions
k15acommented, Apr 5, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found