source: trip-planner-front/node_modules/webpack/lib/container/ModuleFederationPlugin.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
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
8const isValidExternalsType = require("../../schemas/plugins/container/ExternalsType.check.js");
9const SharePlugin = require("../sharing/SharePlugin");
10const createSchemaValidation = require("../util/create-schema-validation");
11const ContainerPlugin = require("./ContainerPlugin");
12const ContainerReferencePlugin = require("./ContainerReferencePlugin");
13
14/** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ExternalsType} ExternalsType */
15/** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ModuleFederationPluginOptions} ModuleFederationPluginOptions */
16/** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").Shared} Shared */
17/** @typedef {import("../Compiler")} Compiler */
18
19const validate = createSchemaValidation(
20 require("../../schemas/plugins/container/ModuleFederationPlugin.check.js"),
21 () => require("../../schemas/plugins/container/ModuleFederationPlugin.json"),
22 {
23 name: "Module Federation Plugin",
24 baseDataPath: "options"
25 }
26);
27class ModuleFederationPlugin {
28 /**
29 * @param {ModuleFederationPluginOptions} options options
30 */
31 constructor(options) {
32 validate(options);
33
34 this._options = options;
35 }
36
37 /**
38 * Apply the plugin
39 * @param {Compiler} compiler the compiler instance
40 * @returns {void}
41 */
42 apply(compiler) {
43 const { _options: options } = this;
44 const library = options.library || { type: "var", name: options.name };
45 const remoteType =
46 options.remoteType ||
47 (options.library && isValidExternalsType(options.library.type)
48 ? /** @type {ExternalsType} */ (options.library.type)
49 : "script");
50 if (
51 library &&
52 !compiler.options.output.enabledLibraryTypes.includes(library.type)
53 ) {
54 compiler.options.output.enabledLibraryTypes.push(library.type);
55 }
56 compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => {
57 if (
58 options.exposes &&
59 (Array.isArray(options.exposes)
60 ? options.exposes.length > 0
61 : Object.keys(options.exposes).length > 0)
62 ) {
63 new ContainerPlugin({
64 name: options.name,
65 library,
66 filename: options.filename,
67 runtime: options.runtime,
68 exposes: options.exposes
69 }).apply(compiler);
70 }
71 if (
72 options.remotes &&
73 (Array.isArray(options.remotes)
74 ? options.remotes.length > 0
75 : Object.keys(options.remotes).length > 0)
76 ) {
77 new ContainerReferencePlugin({
78 remoteType,
79 remotes: options.remotes
80 }).apply(compiler);
81 }
82 if (options.shared) {
83 new SharePlugin({
84 shared: options.shared,
85 shareScope: options.shareScope
86 }).apply(compiler);
87 }
88 });
89 }
90}
91
92module.exports = ModuleFederationPlugin;
Note: See TracBrowser for help on using the repository browser.