UNPKG

hot-accept-webpack-plugin

Version:

With ease add HMR accepting code to need modules

55 lines 2.2 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); exports.__esModule = true; exports.HotAcceptPlugin = void 0; var modify_source_webpack_plugin_1 = require("modify-source-webpack-plugin"); function createRule(test, operations) { if (typeof test === 'string') { var testString_1 = test.replace(/\\/g, '/'); var testFn = function (module) { var _a; var moduleRequest = (_a = module.userRequest) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, '/'); return moduleRequest ? moduleRequest.endsWith(testString_1) : false; }; return { test: testFn, operations: operations }; } return { test: test, operations: operations }; } var HotAcceptPlugin = /** @class */ (function (_super) { __extends(HotAcceptPlugin, _super); function HotAcceptPlugin(options) { var _this = this; var operations = [ new modify_source_webpack_plugin_1.ConcatOperation('end', 'if (module.hot) { module.hot.accept(); }') ]; var rules = Array.isArray(options.test) ? options.test.map(function (test) { return createRule(test, operations); }) : [createRule(options.test, operations)]; _this = _super.call(this, { rules: rules, debug: options.debug }) || this; return _this; } return HotAcceptPlugin; }(modify_source_webpack_plugin_1.ModifySourcePlugin)); exports.HotAcceptPlugin = HotAcceptPlugin; //# sourceMappingURL=HotAcceptPlugin.js.map