Skip to content

Commit

Permalink
build(minor): upgrade ModuleFederation plugin and Webpack to v5.74.0 (#…
Browse files Browse the repository at this point in the history
…1900)

* build(minor): upgrade webpack to 5.74.0 and modulefederation plugin

* fix formatting
  • Loading branch information
mristic505 authored Aug 3, 2022
1 parent 6fce775 commit 36f2742
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/xarc-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 23 additions & 25 deletions packages/xarc-webpack/src/container/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -22,8 +22,6 @@ export class ModuleFederationPlugin {
* @param {ModuleFederationPluginOptions} options options
*/
constructor(options) {
// validate(schema, options, { name: "Module Federation Plugin" });

this._options = options;
}

Expand All @@ -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)
Expand All @@ -70,6 +67,7 @@ export class ModuleFederationPlugin {
) {
new ContainerReferencePlugin({
remoteType,
shareScope: options.shareScope,
remotes: options.remotes
}).apply(compiler);
}
Expand Down

0 comments on commit 36f2742

Please sign in to comment.