vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.16k stars 26.74k forks source link

Styled-jsx is always getting bundled, even if you don't use it #3394

Closed arsen closed 6 years ago

arsen commented 6 years ago

I don't know why but styled-jsx is always getting bundled in. Even if you don't use it at all. Looking into the example from next.js https://github.com/zeit/next.js/tree/canary/examples/with-webpack-bundle-size-analyzer which has just simple pages without any styles, still includes styled-jsx (~21kb).

Is there a way to avoid this?

faker: 1.3 MB (76.2%) next: 99.9 KB (5.72%) react-dom: 91.86 KB (5.26%) core-js: 74.87 KB (4.29%) regenerator-runtime: 24.61 KB (1.41%) url: 23.08 KB (1.32%) styled-jsx: 21.05 KB (1.21%) <<<<<<<<<<<<< punycode: 14.33 KB (0.821%) fbjs: 10.93 KB (0.626%) ..... .....

HoraceShmorace commented 6 years ago

I was considering converting [a major brand website] over to use Next, but after struggling for a week, it's just way too opinionated about things like this. It's a great universal rendering solution, but it forces (or makes strong suggestions regarding) too many other things, like state management and CSS. Out-of-the-box support for stuff is only good if you actually want that stuff. I'd love to just extract the universal rendering piece.

ghost commented 6 years ago

You're way too kind, Horace.

styfle commented 6 years ago

@HoraceShmorace I wrote an example boilerplate with TypeScript + React SSR that might be a good place for you to start.

Check it out here: https://github.com/styfle/react-server-example-tsx

jonjamz commented 6 years ago

Not sure why a style lib is chosen/bundled into Next at all. Seems out of scope, especially when there are so many ways to do styles.

timneutkens commented 6 years ago

styled-jsx is no longer included in client bundles if it's not used. The flush method is executed. I've created https://github.com/zeit/styled-jsx/issues/468 to investigate compiling it away on the server compilation.