UNPKG

@macrof/loader

Version:

React MicroFrontend Loader, Typescript, Webpack 5, ModuleFederation

30 lines (29 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = (target, name) => { var _a, _b, _c; const key = `__${name}__`; window[key] = (_a = window[key]) !== null && _a !== void 0 ? _a : {}; const insertedStyle = window[key]; insertedStyle.elements = (_b = insertedStyle.elements) !== null && _b !== void 0 ? _b : []; insertedStyle.targets = (_c = insertedStyle.targets) !== null && _c !== void 0 ? _c : []; if (target && !insertedStyle.targets.includes(target)) { insertedStyle.targets.push(target); } const inserted = {}; insertedStyle.elements.forEach((style) => { if (style.tagName === 'LINK') { try { document.head.removeChild(style); } catch (e) { console.warn(e); } } const keyT = style.href || style.innerText; if (!inserted[keyT]) { inserted[keyT] = true; target === null || target === void 0 ? void 0 : target.appendChild(style.cloneNode(true)); } }); };