webpack index.html空白,javascript – 为什么React Webpack生产版本显示空白页面?

我正在构建一个反应应用程序,目前webpack-dev-server工作正常(hello world文本显示),但webpack -p显示空白页面.对于生成版本,chrome dev工具下的网络选项卡显示index.html和index_bundle.js的大小为0 B(见图片)eei4z.jpg但显然并非如此.HTML文件大小为227 B& index_bundle.js文件大小为195Kb(见图)766rz.jpg

此外,Chrome Devtools Elements标签显示以下内容(见图片)

bdmHu.jpg

我的webpack配置文件如下所示:Rn1Yo.jpg

解决方法:

我想通了,我在没有设置本地服务器的情况下使用了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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值