UNPKG

@module-federation/enhanced

Version:

This package provides enhanced features for module federation.

43 lines (41 loc) 1.96 kB
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } }); const require_runtime = require('../_virtual/_rolldown/runtime.js'); let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path"); //#region src/wrapper/BaseWrapperPlugin.ts const lazyRequire = (id) => module.require(id); /** * Base Wrapper Plugin Class * * Why we need a Wrapper layer: * 1. Prevent direct references to peer dependency webpack in CommonJS environment, which can lead to inconsistent instances * 2. Ensure the FEDERATION_WEBPACK_PATH environment variable is set correctly, which is crucial for module federation to work properly * 3. Provide unified plugin initialization logic, reducing code duplication * * Why we need to set FEDERATION_WEBPACK_PATH: * In CommonJS environment, require('webpack') might get a different webpack version than the current compiler instance, * which can cause module federation to malfunction. By setting FEDERATION_WEBPACK_PATH, we ensure all internal * dependencies use the same webpack instance as the current compiler. */ var BaseWrapperPlugin = class { constructor(options, pluginName, coreModulePath) { this._options = options; this.pluginName = pluginName; this.coreModulePath = coreModulePath; this.name = pluginName; } apply(compiler) { process.env["FEDERATION_WEBPACK_PATH"] = process.env["FEDERATION_WEBPACK_PATH"] || (0, _module_federation_sdk_normalize_webpack_path.getWebpackPath)(compiler); const CorePlugin = lazyRequire(this.coreModulePath).default; this.createCorePluginInstance(CorePlugin, compiler); } /** * Create core plugin instance * Subclasses can override this method to customize instantiation logic */ createCorePluginInstance(CorePlugin, compiler) { new CorePlugin(this._options).apply(compiler); } }; //#endregion exports.default = BaseWrapperPlugin; //# sourceMappingURL=BaseWrapperPlugin.js.map