新手,多多包涵。
浏览器控制台会出现:
[WDS] App updated. Recompiling...
[WDS] App hot update...
但内容无变更 需手动刷新
配置如下:
webpack.config.js热加载部分代码:
if(isDev) {
config.entry = {
app : [
'react-hot-loader/patch',
path.join(__dirname, '../client/app.js')
]
}
config.devServer = {
host: '0.0.0.0',
port: '8080',
contentBase: path.join(__dirname,'../dist'),
hot:true,
overlay:{
errors: true
},
publicPath:'/public/',
historyApiFallback: {
index: '/public/index.html'
}
}
config.plugins.push(new webpack.HotModuleReplacementPlugin())
}
app.js代码:
import React from 'react'
import ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import App from './App.jsx'
const root = document.getElementById("root")
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<Component />
</AppContainer>,root)
}
render(App)
if(module.hot) {
module.hot.accept('./App.jsx', () =>{
const NextApp = require('./App.jsx').default;
render(NextApp)
})
}
老鸟请解答一下,万谢!