Skip to content

Commit

Permalink
fix: avoid reload all css when hot load
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Mar 20, 2024
1 parent 8bf0ad6 commit cfd1040
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ const MiniCssExtractPlugin = require("./index");
* @returns {string}
*/
function hotLoader(content, context) {
const accept = context.locals
const hasLocals = !!(context.locals && Object.keys(context.locals).length);
const accept = hasLocals
? ""
: "module.hot.accept(undefined, cssReload);";
: "module.hot.accept();";

return `${content}
if(module.hot) {
Expand All @@ -56,7 +57,7 @@ function hotLoader(content, context) {
path.join(__dirname, "hmr/hotModuleReplacement.js")
)})(module.id, ${JSON.stringify({
...context.options,
locals: !!context.locals,
locals: hasLocals,
})});
module.hot.dispose(cssReload);
${accept}
Expand Down

0 comments on commit cfd1040

Please sign in to comment.