我正在构建一个反应应用程序,目前webpack-dev-server工作正常(hello world文本显示),但webpack -p显示空白页面.对于生成版本,chrome dev工具下的网络选项卡显示index.html和index_bundle.js的大小为0 B(见图片)但显然并非如此.HTML文件大小为227 B& index_bundle.js文件大小为195Kb(见图)
此外,Chrome Devtools Elements标签显示以下内容(见图片)
我的webpack配置文件如下所示:
解决方法:
我想通了,我在没有设置本地服务器的情况下使用了browserHistory.如果我把它改成hashHistory它就有效了.要使用react-router浏览器历史记录在本地测试webpack生产,我需要这样做配置服务器:
您的服务器必须准备好处理真实的URL.当应用程序首次加载/它可能会工作,但当用户导航,然后在/ accounts / 23点击刷新时,您的Web服务器将收到/ accounts / 23的请求.您将需要它来处理该URL并在响应中包含您的JavaScript应用程序.
快递应用可能如下所示:
const express = require('express')
const path = require('path')
const port = process.env.PORT || 8080
const app = express()
// serve static assets normally
app.use(express.static(__dirname + '/public'))
// handle every other route with index.html, which will contain
// a script tag to your application's JavaScript file(s).
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
app.listen(port)
console.log("server started on port " + port)
如果有人使用带路由器历史记录的react-router部署到firebase,请执行以下操作:
{
"firebase": "",
"public": "",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
标签:javascript,reactjs,webpack,redux,web-applications
来源: https://codeday.me/bug/20190928/1827415.html