mini-css-extract-plugin icon indicating copy to clipboard operation
mini-css-extract-plugin copied to clipboard

feat: hmr, compare old locals to invalidate if needed

Open goloveychuk opened this issue 4 years ago • 4 comments

This PR contains a:

  • [ ] bugfix
  • [x] new feature
  • [ ] code refactor
  • [ ] test update
  • [ ] typo fix
  • [ ] metadata update

Motivation / Use-Case

This allows self accept css module if locals didn't changed. If changed - propagate. Inspired by https://github.com/webpack-contrib/style-loader/blob/master/src/index.js#L231 Now new runtime is

// extracted by mini-css-extract-plugin
    if(true) {
      // 1612290403401
      var cssReload = __webpack_require__(/*! ../node_modules/mini-css-extract-plugin/dist/hmr/hotModuleReplacement.js */ "../node_modules/mini-css-extract-plugin/dist/hmr/hotModuleReplacement.js")(module.id, {"publicPath":"","esModule":false,"locals":false});
      var _locals = undefined;
      var isEqualLocals = __webpack_require__(/*! ../node_modules/mini-css-extract-plugin/dist/hmr/isEqualLocals.js */ "../node_modules/mini-css-extract-plugin/dist/hmr/isEqualLocals.js");
      module.hot.dispose(function(data) {
        cssReload();
        data.oldLocals = _locals;
      });
      
      if (!_locals || module.hot.invalidate) {
        if (module.hot.invalidate &&
            module.hot.data &&
            module.hot.data.oldLocals &&
            !isEqualLocals(module.hot.data.oldLocals, _locals)) {
            module.hot.invalidate();
        } else {
          module.hot.accept();
        }
      }
    }
  //# sourceURL=[module]
//# sourceMappingURL=data:applicati

Breaking Changes

Additional Info

goloveychuk avatar Feb 02 '21 18:02 goloveychuk

@alexander-akait could you please review? Should I fix tests first (look like all of them are code snapshots)

goloveychuk avatar Feb 05 '21 11:02 goloveychuk

printed output, image

goloveychuk avatar Feb 05 '21 13:02 goloveychuk

@alexander-akait could you please review?

goloveychuk avatar Feb 09 '21 15:02 goloveychuk

@goloveychuk Sorry for delay, apparently I missed a notification somewhere :disappointed: , do not hesitate to ping me again, do you want to finish this?

alexander-akait avatar Jun 25 '21 13:06 alexander-akait