首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在IIS服务器中使用webpack部署react应用程序的白色页面

在IIS服务器中使用webpack部署react应用程序的白色页面
EN

Stack Overflow用户
提问于 2021-04-08 20:40:58
回答 1查看 283关注 0票数 0

我试图使用ModuleFederationPlugin和webpack部署一个基于微前沿的react应用程序,但是当我试图孤立地部署一个微前端时,我会得到一个没有错误的白色页面。

我的webpack配置到生产:

代码语言:javascript
复制
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共通:

代码语言:javascript
复制
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'
        })
    ]
}

我的App.js组件与React路由器:

代码语言:javascript
复制
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控制台没有错误

EN

回答 1

Stack Overflow用户

发布于 2022-09-05 14:10:01

尝试在package.json文件中添加或更改主页属性。使用homepage: '.';将其设置为相对路径。

如果在完成此操作后仍然得到一个白色页,则可能没有设置路由器的basename:

代码语言:javascript
复制
<Router basename='/name' history={history}>
   <Switch>
       <Route exact path="/Microfrontends/marketing/pricing" component={Pricing} />
       <Route path="/Microfrontends/marketing/" component={Landing} />
   </Switch>
</Router>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67011583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档