How to allow for webpack-dev-server to allow entry points from react-router

后端 未结 9 1991
無奈伤痛
無奈伤痛 2020-12-04 05:15

I\'m creating an app that uses webpack-dev-server in development alongside react-router.

It seems that webpack-dev-server is built around the assumption that you wil

9条回答
  •  误落风尘
    2020-12-04 05:59

    If you're running webpack-dev-server using CLI, you can configure it through webpack.config.js passing devServer object:

    module.exports = {
      entry: "index.js",
      output: {
        filename: "bundle.js"
      },
      devServer: {
        historyApiFallback: true
      }
    }

    This will redirect to index.html everytime it 404 is encountered.

    NOTE: If you're using publicPath, you'll need to pass it to devServer too:

    module.exports = {
      entry: "index.js",
      output: {
        filename: "bundle.js",
        publicPath: "admin/dashboard"
      },
      devServer: {
        historyApiFallback: {
          index: "admin/dashboard"
        }
      }
    }

    You can verify that everything is setup correctly by looking at the first few lines of the output (the part with "404s will fallback to: path").

提交回复
热议问题