From 36f27425d0c258c74f5cf1567126511feb588000 Mon Sep 17 00:00:00 2001 From: mristic505 Date: Wed, 3 Aug 2022 18:26:32 -0400 Subject: [PATCH] build(minor): upgrade ModuleFederation plugin and Webpack to v5.74.0 (#1900) * build(minor): upgrade webpack to 5.74.0 and modulefederation plugin * fix formatting --- packages/xarc-webpack/package.json | 2 +- .../src/container/ModuleFederationPlugin.ts | 48 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/xarc-webpack/package.json b/packages/xarc-webpack/package.json index 0a55d6a95..bb7e03d03 100644 --- a/packages/xarc-webpack/package.json +++ b/packages/xarc-webpack/package.json @@ -51,7 +51,7 @@ "optional-require": "^1.1.6", "require-at": "^1.0.6", "url-loader": "^4.1.0", - "webpack": "^5.33.2", + "webpack": "^5.74.0", "webpack-cli": "4.8.0", "webpack-config-composer": "^1.1.6", "webpack-stats-plugin": "^1.0.3", diff --git a/packages/xarc-webpack/src/container/ModuleFederationPlugin.ts b/packages/xarc-webpack/src/container/ModuleFederationPlugin.ts index 16526dc66..e96450341 100644 --- a/packages/xarc-webpack/src/container/ModuleFederationPlugin.ts +++ b/packages/xarc-webpack/src/container/ModuleFederationPlugin.ts @@ -5,7 +5,7 @@ /* eslint-disable */ // const { validate } = require("schema-utils"); -const schema = require("webpack/schemas/plugins/container/ModuleFederationPlugin.json"); +const isValidExternalsType = require("webpack/schemas/plugins/container/ExternalsType.check.js"); const SharePlugin = require("webpack/lib/sharing/SharePlugin"); const ContainerReferencePlugin = require("webpack/lib/container/ContainerReferencePlugin"); @@ -22,8 +22,6 @@ export class ModuleFederationPlugin { * @param {ModuleFederationPluginOptions} options options */ constructor(options) { - // validate(schema, options, { name: "Module Federation Plugin" }); - this._options = options; } @@ -38,30 +36,29 @@ export class ModuleFederationPlugin { const library = options.library || { type: "var", name: options.name }; const remoteType = - options.remoteType || - (options.library && schema.definitions.ExternalsType.enum.includes(options.library.type) - ? /** @type {ExternalsType} */ options.library.type - : "script"); - - if (library && !compiler.options.output.enabledLibraryTypes.includes(library.type)) { + options.remoteType || + (options.library && isValidExternalsType(options.library.type) + ? /** @type {ExternalsType} */ (options.library.type) + : "script"); + if (library && !compiler.options.output.enabledLibraryTypes.includes(library.type)) { compiler.options.output.enabledLibraryTypes.push(library.type); } - - compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => { - if ( - options.exposes && - (Array.isArray(options.exposes) - ? options.exposes.length > 0 - : Object.keys(options.exposes).length > 0) - ) { - new ContainerPlugin({ - name: options.name, - entry: options.entry, - library, - filename: options.filename, - exposes: options.exposes - }).apply(compiler); - } + compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => { + if ( + options.exposes && + (Array.isArray(options.exposes) + ? options.exposes.length > 0 + : Object.keys(options.exposes).length > 0) + ) { + new ContainerPlugin({ + name: options.name, + library, + filename: options.filename, + runtime: options.runtime, + shareScope: options.shareScope, + exposes: options.exposes + }).apply(compiler); + } if ( options.remotes && (Array.isArray(options.remotes) @@ -70,6 +67,7 @@ export class ModuleFederationPlugin { ) { new ContainerReferencePlugin({ remoteType, + shareScope: options.shareScope, remotes: options.remotes }).apply(compiler); }