Repository navigation
fix: avoid reloading all csses when hot load - #1090
Conversation
| const hasLocals = !!(context.locals && Object.keys(context.locals).length); | ||
| const accept = hasLocals | ||
| ? "" | ||
| : "module.hot.accept(undefined, cssReload);"; |
There was a problem hiding this comment.
self accept is enough, it will update when dispose: https://webpack.js.org/api/hot-module-replacement/
alexander-akait
left a comment
There was a problem hiding this comment.
We need a test case, please add
test cases updated |
| const localsJsonString = ${localsJsonString}; | ||
| // ${Date.now()} | ||
| var cssReload = require(${stringifyRequest( | ||
| const cssReload = require(${stringifyRequest( |
There was a problem hiding this comment.
Don't use const, it will be in the browser and break old browsers
| ? "" | ||
| : "module.hot.accept(undefined, cssReload);"; | ||
|
|
||
| const localsJsonString = JSON.stringify(JSON.stringify(context.locals)); |
There was a problem hiding this comment.
Why double JSON.stringify? Just typo?
There was a problem hiding this comment.
note the interpolation:
`const localsJsonString = ${localsJsonString};`string comparation is faster
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1090 +/- ##
==========================================
+ Coverage 90.61% 92.00% +1.38%
==========================================
Files 5 5
Lines 895 900 +5
Branches 255 258 +3
==========================================
+ Hits 811 828 +17
+ Misses 74 67 -7
+ Partials 10 5 -5 ☔ View full report in Codecov by Sentry. |
| module.hot.dispose(function(data) { | ||
| data.value = localsJsonString; | ||
| cssReload(); | ||
| }); |
There was a problem hiding this comment.
We have a special test directory for HMR, will be great to add a test case there, I know your code works fine, but we should ensure about it
There was a problem hiding this comment.
what do you mean? I have added cases inside cases folder (hmr, hmr-locals)
There was a problem hiding this comment.
Sorry for delay, just put a test case here https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/test/HMR.test.js
There was a problem hiding this comment.
Sorry for delay, just put a test case here https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/test/HMR.test.js
done
alexander-akait
left a comment
There was a problem hiding this comment.
Let's do small improvements and I am fine with it
|
For fixing tests for OLD API just use |
|
Thank you for your PR |
passed |
|
@yiminghe We have: As you can see it is an absolute path, let's use it from here https://github.com/webpack-contrib/css-loader/blob/master/src/utils.js#L15 (maybe we already have the same util here) |
updated |
This PR contains a:
Motivation / Use-Case
Breaking Changes
Additional Info
Fixes #692