在 IIS 服务器中使用 webpack 部署 React 应用程序的白页

问题描述

我正在尝试使用 ModuleFederationPlugin 和 webpack 部署基于微前端的 React Web 应用程序,但是当我尝试单独部署其中一个微前端时,我得到一个没有错误的白页。

我的 webpack 配置到生产:

const { merge } = require('webpack-merge')
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin')
const commonConfig = require('./webpack.common')
const packageJson = require('../package.json')

const prodConfig = {
    mode: 'production',output: {
        filename: '[name].[contenthash].js',publicPath: '/Microfrontends/marketing/'
    },plugins: [
        new ModuleFederationPlugin({
            name: 'marketing',filename: 'remoteEntry.js',exposes: {
                './MarketingModule': './src/bootstrap'
            },shared: packageJson.dependencies
        })
    ]
}

module.exports = merge(commonConfig,prodConfig)

我的 webpack 与 babel 的共同点:

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    module: {
        rules: [
            {
                test: /\.m?js$/,exclude: /node_modules/,use: {
                    loader: 'babel-loader',options: {
                        presets: ['@babel/preset-react','@babel/preset-env'],plugins: ['@babel/plugin-transform-runtime']
                    }
                }
            }
        ]
    },plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html'
        })
    ]
}

我的带有 React-Router 的 App.js 组件:

export default function App({ history }) {
    return (
        <Fragment>
            <StylesProvider generateClassName={generateClassName}>
                <Router history={history}>
                    <Switch>
                        <Route exact path="/Microfrontends/marketing/pricing" component={Pricing} />
                        <Route path="/Microfrontends/marketing/" component={Landing} />
                    </Switch>
                </Router>
            </StylesProvider>
        </Fragment>
    )
}

当我在服务器中部署时,所有状态请求都是 200 并且 chrome 控制台没有错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...