Skip to content
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

[v2] use MiniCssExtractPlugin only on production builds #5057

Merged
merged 1 commit into from
Apr 22, 2018

Conversation

nihgwu
Copy link
Contributor

@nihgwu nihgwu commented Apr 20, 2018

MiniCssExtractPlugin should be used on production builds only as it doesn't support HMR right now, we can remove the fallback to style-loader when it supports HMR

https://github.com/webpack-contrib/mini-css-extract-plugin#advanced-configuration-example
webpack-contrib/mini-css-extract-plugin#100

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea — might be a little while until HMR is finished.

@@ -8,7 +8,6 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.42",
"mini-css-extract-plugin": "^0.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was it removed here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i they are following through with my changes in #4971 where i missed this one 😳

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha 👍

@jquense
Copy link
Contributor

jquense commented Apr 20, 2018

code looks fine, thou maybe this isn't necessary? the plugin works with incremental builds, though yes it requires a hard refresh. Part of me thinks it's nicer to have them always extracted since it'll much closer to what the prod build will be, plus no flash of unstyled content.

@nihgwu
Copy link
Contributor Author

nihgwu commented Apr 20, 2018

@jquense Yes I agree it's nicer to keep the behavior the same in different stage, I thought about adding a option to turn off the fallback to style-loader, but in practice we trend to only use text extract plugin in production only, we can change a bit to remove the fallback when the library supports HMR
BTW, apart from this, the original code is broken, as you access disable and other options while options is not provided, also seem disable and fallback is for the old text extract plugin? I don't find they are valid options for mini extract plugin

@jquense
Copy link
Contributor

jquense commented Apr 20, 2018

but in practice we trend to only use text extract plugin in production only

Sure, but most of the reason for that is the the old extract -text just couldn't be used reasonably outside of Prod, not because it makes sense to only use it there. I just wanted to chat a bit about the options here, reasonably i think that if we hit v2 and HMR is added after we can't update the default config without it being a breaking change (on the cautious side), If HMR is coming reasonably soon i'd say we should just keep it and wait for the improvement, but that's just me. Personally i think style-loader mostly causes issues (and dev only ones at that), i'd prefer the hard reload with a path towards the same thing automatically further on over using style-loader.

also seem disable and fallback is for the old text extract plugin

Yeah they are old, likely some plugins didn't get upgraded when the original PR switched the plugins out.

@KyleAMathews
Copy link
Contributor

I'm a bit indifferent about this PR too — though I only do css-in-js so don't feel any pain from CSS HMR not working :-D — I know Tobias wants to get HMR in fairly quickly 🤷‍♂️ I also don't think it'd be a breaking change to swap styled-loader out for native HMR once it's ready so...

@nihgwu
Copy link
Contributor Author

nihgwu commented Apr 21, 2018

I only use styled-components too, but I'm building a website for a library using sass, so I need css HMR, I think the switching to style-loader in development is legit as when HMR is ready from mini css plugin, we can simply remove the tweak

Any thoughts on this? or should I just remove the style-loader to only apply the other fixes?

@KyleAMathews KyleAMathews merged commit ade2925 into gatsbyjs:v2 Apr 22, 2018
@KyleAMathews
Copy link
Contributor

Yeah, this seems fine for now — we'll remove it soon enough.

@nihgwu nihgwu deleted the neo/css-exact-hmr branch April 22, 2018 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants