2020-02-27 06:28:36 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const ContainerPlugin = require("./ContainerPlugin");
|
|
|
|
const ContainerReferencePlugin = require("./ContainerReferencePlugin");
|
|
|
|
|
|
|
|
/** @typedef {import("../Compiler")} Compiler */
|
|
|
|
|
|
|
|
class ModuleFederationPlugin {
|
|
|
|
constructor(options) {
|
|
|
|
// TODO options validation
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Compiler} compiler webpack compiler
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
apply(compiler) {
|
|
|
|
const { options } = this;
|
|
|
|
new ContainerPlugin({
|
|
|
|
name: options.name,
|
2020-04-02 05:36:40 +08:00
|
|
|
library: options.library,
|
2020-02-27 06:28:36 +08:00
|
|
|
filename: options.filename,
|
|
|
|
exposes: options.exposes,
|
2020-04-01 00:57:09 +08:00
|
|
|
overridables: options.shared
|
2020-02-27 06:28:36 +08:00
|
|
|
}).apply(compiler);
|
|
|
|
new ContainerReferencePlugin({
|
2020-04-01 00:47:16 +08:00
|
|
|
remoteType:
|
2020-04-04 07:27:51 +08:00
|
|
|
options.remoteType ||
|
|
|
|
(options.library && options.library.type) ||
|
|
|
|
compiler.options.externalsType,
|
2020-02-27 06:28:36 +08:00
|
|
|
remotes: options.remotes,
|
2020-04-01 00:57:09 +08:00
|
|
|
overrides: options.shared
|
2020-02-27 06:28:36 +08:00
|
|
|
}).apply(compiler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ModuleFederationPlugin;
|