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

后端 未结 9 1994
無奈伤痛
無奈伤痛 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 06:03

    This worked for me: just simply add the webpack middlewares first and the app.get('*'... index.html resolver later,

    so express will first check if the request matches one of the routes provided by webpack (like: /dist/bundle.js or /__webpack_hmr_) and if not, then it will move to the index.html with the * resolver.

    ie:

    app.use(require('webpack-dev-middleware')(compiler, {
      publicPath: webpackConfig.output.publicPath,
    }))
    app.use(require('webpack-hot-middleware')(compiler))
    app.get('*', function(req, res) {
      sendSomeHtml(res)
    })
    

提交回复
热议问题