Skip to content

Instantly share code, notes, and snippets.

@harshq
Created July 25, 2021 06:43
Show Gist options
  • Save harshq/343784d01965fdf99705c9ba11504812 to your computer and use it in GitHub Desktop.
Save harshq/343784d01965fdf99705c9ba11504812 to your computer and use it in GitHub Desktop.
Module federation with Webpack 5
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const dependencies = require("./package.json").dependencies;
const PORT = 3001;
module.exports = {
entry: path.resolve(__dirname, "./src/index.js"),
devServer: {
contentBase: path.join(__dirname, "dist"),
port: PORT,
},
output: {
publicPath: "auto",
},
resolve: {
extensions: [".js", ".jsx"],
},
module: {
rules: [
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
],
},
plugins: [
new ModuleFederationPlugin({
name: "mfe",
exposes: {},
filename: "remoteEntry.js",
shared: {
...dependencies,
react: {
singleton: true,
eager: true,
requiredVersion: dependencies["react"],
},
"react-dom": {
singleton: true,
eager: true,
requiredVersion: dependencies["react-dom"],
},
},
}),
new HtmlWebpackPlugin({
manifest: "./public/manifest.json",
favicon: "./public/favicon.ico",
template: "./public/index.html",
}),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment