Files
emaui/node_modules/@module-federation/rspack/dist/RemoteEntryPlugin.js
2026-05-29 15:23:46 +03:00

128 lines
4.3 KiB
JavaScript

"use strict";
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
return typeof document === 'undefined'
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
: (document.currentScript && document.currentScript.src) ||
new URL('main.js', document.baseURI).href;
})();
;
// The require scope
var __webpack_require__ = {};
/************************************************************************/
// webpack/runtime/compat_get_default_export
(() => {
// getDefaultExport function for compatibility with non-ESM modules
__webpack_require__.n = (module) => {
var getter = module && module.__esModule ?
() => (module['default']) :
() => (module);
__webpack_require__.d(getter, { a: getter });
return getter;
};
})();
// webpack/runtime/define_property_getters
(() => {
__webpack_require__.d = (exports, definition) => {
for(var key in definition) {
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
}
}
};
})();
// webpack/runtime/has_own_property
(() => {
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
})();
// webpack/runtime/make_namespace_object
(() => {
// define __esModule on exports
__webpack_require__.r = (exports) => {
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
}
Object.defineProperty(exports, '__esModule', { value: true });
};
})();
/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
RemoteEntryPlugin: () => (/* binding */ RemoteEntryPlugin)
});
;// CONCATENATED MODULE: external "@module-federation/managers"
const managers_namespaceObject = require("@module-federation/managers");
;// CONCATENATED MODULE: external "./logger.js"
const external_logger_js_namespaceObject = require("./logger.js");
var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
;// CONCATENATED MODULE: ./src/RemoteEntryPlugin.ts
// @ts-ignore
const charMap = {
'<': '\\u003C',
'>': '\\u003E',
'/': '\\u002F',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
};
function escapeUnsafeChars(str) {
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, (x)=>charMap[x]);
}
class RemoteEntryPlugin {
static addPublicPathEntry(compiler, getPublicPath, name) {
let code;
const sanitizedPublicPath = escapeUnsafeChars(getPublicPath);
if (!getPublicPath.startsWith('function')) {
code = `${compiler.webpack.RuntimeGlobals.publicPath} = new Function(${JSON.stringify(sanitizedPublicPath)})()`;
} else {
code = `(${sanitizedPublicPath}())`;
}
const base64Code = Buffer.from(code, 'utf8').toString('base64');
const dataUrl = `data:text/javascript;base64,${base64Code}`;
compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', ()=>{
new compiler.webpack.EntryPlugin(compiler.context, dataUrl, {
name: name
}).apply(compiler);
});
}
apply(compiler) {
const { name, getPublicPath } = this._options;
if (!getPublicPath || !name) {
return;
}
const containerManager = new managers_namespaceObject.ContainerManager();
containerManager.init(this._options);
if (!containerManager.enable) {
external_logger_js_default().warn("Detect you don't set exposes, 'getPublicPath' will not have effect.");
return;
}
RemoteEntryPlugin.addPublicPathEntry(compiler, getPublicPath, name);
}
constructor(options){
this.name = 'VmokRemoteEntryPlugin';
this._options = options;
}
}
exports.RemoteEntryPlugin = __webpack_exports__.RemoteEntryPlugin;
for(var __webpack_i__ in __webpack_exports__) {
if(["RemoteEntryPlugin"].indexOf(__webpack_i__) === -1) {
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
}
}
Object.defineProperty(exports, '__esModule', { value: true });