Webpack 开发服务器问题

Webpack Dev Server Issues

我正在使用 Express + React 构建 Web 应用程序。

我正在处理 WEbpack 开发服务器的问题。

我的 Webpack Dev Server 可以很好地构建捆绑包! 但是,我对提供文件的方式有疑问。

通常,我们将根 html 文件命名为 index.html,但由于我的 Web 应用程序架构,我不能使用 index.html 而是将其命名为 client.html .

这让我想到了我面临的问题,webpack 开发服务器在我转到 localhost:8080 时寻找 index.html,因为我正在使用 client.html webpack 开发服务器服务要求我 select 我的文件。

Webpack Static file select screen

所以,有没有办法在我访问localhost:8080(Webpack Dev Server)时直接加载client.html。

提前致谢!

在您的 webpack.config.js 文件中,您可以添加 webpack 开发服务器的配置

devServer: {
  historyApiFallback: {
    rewrites : [
      {from: /^\/$/, to: './client.html'}
    ]
  }
}

这会将您的默认 index.html 重定向到 client.html 有关详细信息,请参阅 DevServer documentation