Skip to content

Commit 836aba6

Browse files
fix(typescript): add ModuleFederationPlugin alongside FederatedTypesPlugin
1 parent 8f94da4 commit 836aba6

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

typescript/app1/webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const HtmlWebpackPlugin = require('html-webpack-plugin');
22
const { FederatedTypesPlugin } = require('@module-federation/typescript');
3+
const { container } = require('webpack');
4+
const { ModuleFederationPlugin } = container;
35
const path = require('path');
46

57
const pkg = require('./package.json');
@@ -37,6 +39,28 @@ module.exports = {
3739
],
3840
},
3941
plugins: [
42+
// Define federation config once and use for both plugins
43+
new ModuleFederationPlugin({
44+
name: 'app1',
45+
filename: 'remoteEntry.js',
46+
remotes: {
47+
app2: 'app2@http://localhost:3002/remoteEntry.js',
48+
},
49+
shared: [
50+
{
51+
react: {
52+
singleton: true,
53+
requiredVersion: pkg.dependencies.react,
54+
},
55+
},
56+
{
57+
'react-dom': {
58+
singleton: true,
59+
requiredVersion: pkg.dependencies['react-dom'],
60+
},
61+
},
62+
],
63+
}),
4064
new FederatedTypesPlugin({
4165
federationConfig: {
4266
name: 'app1',

typescript/app2/webpack.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const HtmlWebpackPlugin = require('html-webpack-plugin');
22
const { FederatedTypesPlugin } = require('@module-federation/typescript');
3+
const { container } = require('webpack');
4+
const { ModuleFederationPlugin } = container;
35
const path = require('path');
46

57
const pkg = require('./package.json');
@@ -37,6 +39,27 @@ module.exports = {
3739
],
3840
},
3941
plugins: [
42+
new ModuleFederationPlugin({
43+
name: 'app2',
44+
filename: 'remoteEntry.js',
45+
exposes: {
46+
'./Button': './src/Button',
47+
},
48+
shared: [
49+
{
50+
react: {
51+
singleton: true,
52+
requiredVersion: pkg.dependencies.react,
53+
},
54+
},
55+
{
56+
'react-dom': {
57+
singleton: true,
58+
requiredVersion: pkg.dependencies['react-dom'],
59+
},
60+
},
61+
],
62+
}),
4063
new FederatedTypesPlugin({
4164
federationConfig: {
4265
name: 'app2',

0 commit comments

Comments
 (0)