use MiniCssExtractPlugin with hmr in dev mode#8148
use MiniCssExtractPlugin with hmr in dev mode#8148vatz88 wants to merge 2 commits intofacebook:masterfrom
Conversation
Remove style-loader
|
Hi vatz88! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
1 similar comment
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
|
Great find. In my mind it's always better if dev and prod are as similar as possible. Do you have any idea if performance is affected? |
|
@andriijas I haven't observed any difference in performance. About the tests which are failing. I see the test code includes |
| : isEnvDevelopment && 'static/css/[name].css', | ||
| chunkFilename: isEnvProduction | ||
| ? 'static/css/[name].[contenthash:8].chunk.css' | ||
| : isEnvDevelopment && 'static/css/[name].chunk.css', |
There was a problem hiding this comment.
Is isEnvDevelopment && necessary?
There was a problem hiding this comment.
Not really, just following the pattern how it's written elsewhere in the code. For example https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js#L194
There was a problem hiding this comment.
Thanks for the reference - I hadn't noticed that. Consistency is indeed important, but I can't help but wonder about the purpose of these checks 🤔
|
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Bad robot! |
|
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
|
@vatz88 can you please update your PR? |
Haven't really gotten time to understand and fix the tests. Will close this PR for now. Though I'd appreciate any help regarding this same. |
|
@vatz88 sorry for not getting back in time. Could you rebase your changes on top of the latest and I will take a look at the tests? thanks |
|
@andriijas Thanks, updated the branch. |
|
Thanks, I will check this later in the week! I have been in a project with standalone webpack configs where we are running minicssextractplugin in dev with hmr working fine for a while so I think this should be the way to go. I will check the tests! |
|
@andriijas just checked this and it seems not working solution for me, because it refreshes page instead of just replacing css like |
|
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
|
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
|
As mentioned in #8378 proper hmr wont be possible in either style-loader or minicssextract plugin until webpack 5 is stable. |
|
I guess it's good to close this PR for now and be worked on when we have stable release of webpack v5. |
Remove
style-loaderand useMiniCssExtractPluginfor both development and production environment.I believe one of the main reasons to use
style-loaderin development mode is to support hot module reloading since styles are in js files. But MiniCssExtractPlugin which is used for production build does support HMR feature since v0.6.0 (2019-04-10).Discussion on spectrum https://spectrum.chat/create-react-app/general/why-react-scripts-webpack-config-uses-style-loader-in-dev-mode-and-not-minicssextractplugin-with-hmr~f966f7b0-0b42-4918-b0be-79e590ed8cdb