@arco-plugins/webpack-react
Version:
arco webpack plugin
42 lines (41 loc) • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReplaceIconPlugin = void 0;
var path_1 = __importDefault(require("path"));
var ReplaceIconPlugin = /** @class */ (function () {
function ReplaceIconPlugin(options) {
this.options = options;
}
ReplaceIconPlugin.prototype.apply = function (compiler) {
var iconBox = this.options.iconBox;
if (!iconBox)
return;
var iconBoxLib;
var iconBoxDirname;
try {
iconBoxDirname = path_1.default.dirname(require.resolve("".concat(iconBox, "/package.json")));
iconBoxLib = require(iconBox); // eslint-disable-line
}
catch (e) {
throw new Error("IconBox ".concat(iconBox, " not existed"));
}
compiler.options.module.rules.unshift({
test: /\.js/,
include: /node_modules\/@arco-design\/web-react\/icon\/react-icon\/([^/]+)\/index\.js$/,
use: [
{
loader: path_1.default.resolve(__dirname, './loaders/replace-icon.js'),
options: {
iconBoxLib: iconBoxLib,
iconBoxDirname: iconBoxDirname,
},
},
],
});
};
return ReplaceIconPlugin;
}());
exports.ReplaceIconPlugin = ReplaceIconPlugin;