@module-federation/nextjs-mf 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy
4
+ */
5
+
6
+ 'use strict';
7
+ /*
8
+ plugin was copied over because ContainerPlugin is called in compiler.hooks.afterPlugins which doest seem to work in child compiler
9
+ */
10
+ /** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ExternalsType} ExternalsType */
11
+ /** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ModuleFederationPluginOptions} ModuleFederationPluginOptions */
12
+
13
+ /** @typedef {import("webpack").Shared} Shared */
14
+ /** @typedef {import("webpack").Compiler} Compiler */
15
+
16
+ class ModuleFederationPlugin {
17
+ /**
18
+ * @param {ModuleFederationPluginOptions} options options
19
+ */
20
+ constructor(options) {
21
+ this._options = options;
22
+ }
23
+
24
+ /**
25
+ * Apply the plugin
26
+ * @param {Compiler} compiler the compiler instance
27
+ * @returns {void}
28
+ */
29
+ apply(compiler) {
30
+ const { _options: options } = this;
31
+ const webpack = compiler.webpack;
32
+ const { ContainerPlugin, ContainerReferencePlugin } = webpack.container;
33
+ const { SharePlugin } = webpack.sharing;
34
+ const library = options.library || { type: 'var', name: options.name };
35
+ const remoteType =
36
+ options.remoteType ||
37
+ (options.library && /** @type {ExternalsType} */ options.library.type) ||
38
+ 'script';
39
+ if (
40
+ library &&
41
+ !compiler.options.output.enabledLibraryTypes.includes(library.type)
42
+ ) {
43
+ compiler.options.output.enabledLibraryTypes.push(library.type);
44
+ }
45
+
46
+ if (
47
+ options.exposes &&
48
+ (Array.isArray(options.exposes)
49
+ ? options.exposes.length > 0
50
+ : Object.keys(options.exposes).length > 0)
51
+ ) {
52
+ new ContainerPlugin({
53
+ name: options.name,
54
+ library,
55
+ filename: options.filename,
56
+ runtime: options.runtime,
57
+ exposes: options.exposes,
58
+ }).apply(compiler);
59
+ }
60
+ if (
61
+ options.remotes &&
62
+ (Array.isArray(options.remotes)
63
+ ? options.remotes.length > 0
64
+ : Object.keys(options.remotes).length > 0)
65
+ ) {
66
+ new ContainerReferencePlugin({
67
+ remoteType,
68
+ remotes: options.remotes,
69
+ }).apply(compiler);
70
+ }
71
+ if (options.shared) {
72
+ new SharePlugin({
73
+ shared: options.shared,
74
+ shareScope: options.shareScope,
75
+ }).apply(compiler);
76
+ }
77
+ }
78
+ }
79
+
80
+ export default ModuleFederationPlugin;