启用单页应用程序反应热重载 webpack [英] Enable single page app react hot reload webpack

查看:37
本文介绍了启用单页应用程序反应热重载 webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 react router 和 webpackdevserver 设置单页 react 应用程序时遇到了一些问题.如果我使用 browserhistory,webpack 在输入嵌套路由 url(例如/client/view)时会出现一些问题.这可以通过添加 apiFallback 来解决,但热重载仍然存在问题.它尝试从不存在的深层 url (/client/view/hot-update.json) 加载 hot-update.json 文件,因此失败并重新加载页面.我如何告诉 hotreload 总是从基本 url (/) 加载 hot-update.json?

I have some problems setting up a single page react app using react router with the webpackdevserver. If I use browserhistory webpack has some problems when entering a nested route url (/client/view for example). This could be solved adding apiFallback but hot reload does still have a problem. It tries to load the hot-update.json file from the deep url (/client/view/hot-update.json) which does not exist and therefor fails and reloads the page. How can i tell hotreload to always load the hot-update.json from the base url (/)?

推荐答案

我在使用 '' 以外的 publicPath 时遇到了类似的问题,我通过添加解决了devServer 选项的代理条目:

I had a similar issue when using a publicPath other than '', which I solved by adding a proxy entry to the devServer options:

devServer: {
  // ... rest of options
  proxy: {
    '/myPublicPath/*': {
      target: 'http://localhost:8080/',
      pathRewrite: { '^/myPublicPath': '' },
  }
}

除此之外,请确保 output.publicPathdevServer.publicPath 设置且相等.

Other than that, make sure both output.publicPath and devServer.publicPath is set and equal.

希望这有帮助!

这篇关于启用单页应用程序反应热重载 webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆