Search
你可以通过如下的命令安装插件:
npm add @module-federation/enhanced
创建 module-federation.config.js 文件,内容如下:
module.export = { name: 'host', remotes: { provider: 'provider@http://localhost:2004/mf-manifest.json', }, exposes: { './Button': './src/components/Button.tsx', }, shared: { react: { singleton: true, }, 'react-dom': { singleton: true, }, }, };
在 Webpack 中,你可以通过 webpack.config.js 配置文件中的 plugins 配置项来添加插件:
Webpack
webpack.config.js
plugins
const { ModuleFederationPlugin, } = require('@module-federation/enhanced/webpack'); const mfConfig = require('./module-federation.config'); module.exports = { devServer: { port: 2000, }, output: { publicPath: 'http://localhost:2000/', }, plugins: [new ModuleFederationPlugin(mfConfig)], };
你可以在 Config 总览 页面找到所有配置项的详细说明。