Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何让webpack dev中间件使用index.html为所有路由提供服务_Reactjs_Express_Webpack_Html Webpack Plugin_Webpack Dev Middleware - Fatal编程技术网

Reactjs 如何让webpack dev中间件使用index.html为所有路由提供服务

Reactjs 如何让webpack dev中间件使用index.html为所有路由提供服务,reactjs,express,webpack,html-webpack-plugin,webpack-dev-middleware,Reactjs,Express,Webpack,Html Webpack Plugin,Webpack Dev Middleware,我正在尝试获取webpack dev middleware来为html webpack plugin为所有路由生成的index.html文件提供服务。例如,localhost:1234/将很好地加载index.html文件,但是如果尝试加载localhost:1234/fooExpress,它会说找不到GET请求的处理程序 在非开发环境中,我的express设置中有一行代码可以解决这个问题 app.get('*', (req, res) => { const indexPath = p

我正在尝试获取
webpack dev middleware
来为
html webpack plugin
为所有路由生成的
index.html
文件提供服务。例如,
localhost:1234/
将很好地加载
index.html
文件,但是如果尝试加载
localhost:1234/foo
Express,它会说找不到GET请求的处理程序

在非开发环境中,我的express设置中有一行代码可以解决这个问题

app.get('*', (req, res) => {
  const indexPath = path.join(
    fs.realpathSync(process.cwd()),
    `${rootDir}/${isProd ? 'public' : 'client'}`,
    'index.html'
  );

  res.sendFile(indexPath);
});
但是使用
webpack-dev-middleware
时,磁盘上没有可供参考的文件,因此会出现故障

我试图使用下面的配置强制
webpack dev middleware
写入磁盘,但我也在运行
nodemon
,出于某种原因,这会导致它每隔15秒左右触发一次重建

  app.use(
    webpackDevMiddleware(compiler, {
      publicPath: webpackConfig.output!.publicPath!,
      writeToDisk: true,
    })
  );
} 
我觉得有一个更优雅的解决方案,我在
webpack dev server
但是中间件没有这个选项