-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
How to make gatsby generate separate css for each static page? #21728
Comments
All css is intentionally bundled into one I'm unsure of how to prevent that happening, the changes that made it happen are here. A more official method might be beneficial for people if they understand the consequences. @KyleAMathews to quote you:
|
Yep, here is a relevant part of the webpack config: gatsby/packages/gatsby/src/utils/webpack.config.js Lines 495 to 507 in 329650b
Seems that the only way to switch to multiple CSS files is by setting custom webpack config. But there is an existing plugin gatsby-plugin-split-css that does exactly this. |
@vladar I tried the plugin and it does exactly what we need, thank you. The reason why we are not worried about style order is because we are using scss modules and our components have unique css classes anyway. We only have 1 global stylesheet which is okay to override by local styles. |
Thank you for opening this! We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby! |
Does anyone have a link to a repository where gatsby plugin split css is working? I just tried it on my repo using |
@ericmasiello that's the bug they linked to (#11072) above in explaining why the styles aren't split by default anymore. |
I am trying gatsby plugin split css and it is working but the only issue is that it is not including the styles like - ../styles/App.scss. It is only working for css modules |
Summary
We have a pretty large project with 200+ pages and a lot of components. We used typestyle in the past but we decided to move to scss because we had a performance problem styles taking too much time on initial load. Problem is that all styles of the site from all pages were inlined into a single
<style>
tag. Unfortunately the problem persisted after moving to scss. We have exactly same issue now, all styles are inlined. We are using scss modules so that all styles have unique ideas per component, but still we want a faster load time.The solution we want to see is that each page would only get styles that are imported in the components used on that page + global styles. When navigating to next page styles should be lazyloaded just like javascript bundle. Is there a way to achieve this now in gatsby?
The text was updated successfully, but these errors were encountered: