我正在尝试设置 webpack 开发服务器,以便:
- 请求
/由public/landing.html(静态登录页面)提供服务 - 我的 React 应用程序处理对任何其他内容的请求
使用create-react-app, 并基于webpack-dev-server's options,我设置webpackDevServer.config.js如下:
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebookincubator/create-react-app/issues/387.
disableDotRule: true,
rewrites: [
// shows views/landing.html as the landing page
{ from: /^\/$/, to: 'landing.html' },
// shows views/subpage.html for all routes starting with /subpage
{ from: /^\/subpage/, to: 'subpage.html' },
// shows views/404.html on all other pages
{ from: /./, to: '404.html' },
],
},
当我启动 webpack 时,我看到的是:
- 请求
/subpage被正确路由到subpage.html - 请求
/foo正确路由到404.html。最终,这些将由我的 React 应用程序处理。 - 请求
/被错误地路由到我的 React 应用程序。
我怎样才能landing.html回应请求/?