React-hot-loader不传播更改

时间:2019-03-24 14:14:03

标签: reactjs webpack webpack-dev-server react-hot-loader

我的问题是react-hot-reload会检测到更改和需要更新的模块,并且显然会更新模块,但是浏览器中没有任何更改。

这是我正在使用的库的版本:

  • 反应-16.8.3
  • react-dom(由react-hot-loader修补)-16.8.3
  • react-hot-loader-4.8.0
  • webpack-4.29.6

下面,我的webpack-dev-server配置:

historyApiFallback: true,
hot: true,
stats: 'none',
quiet: true,
port: port,
host: host,

我的webpack配置的相关部分

entry: [
  'react-hot-loader/patch',
  'webpack-dev-server/client?http://localhost:8080',
  'webpack/hot/only-dev-server',
  './src/index.js',
],
resolve : {
  alias: {
    'react-dom': '@hot-loader/react-dom'
  }
},

我的.babelrc:

"plugins": [
  "@babel/plugin-transform-flow-strip-types",
  "@babel/plugin-proposal-class-properties",
  "react-hot-loader/babel"
]

我的初始组件:

import React, { Component } from 'react'
import { hot } from 'react-hot-loader/root'

class App extends Component<PropTypes, StateTypes> {
  render (): React$Element<*> {
    return (
        <Router>
            <Switch>
                <Route
                    path="/home"
                    render={ (props: Object): React$Element<*> => <HomeView {...props } /> }
                />
                <Route component={ IntroView } />
            </Switch>
        </Router>
    )
  }
}

export default hot(App)

最后,我的输入文件:

import React from 'react'
import ReactDOM from 'react-dom'
import App from './app'

const appContainer = document.getElementById('appContainer')

if (module.hot) {
  module.hot.accept()
  if (appContainer) ReactDOM.render(<App />, appContainer)
} else if (appContainer) {
  ReactDOM.render(<App />, appContainer)
}

如果我做了任何应该触发更新的代码更改,那就是我的控制台:

[WDS] App updated. Recompiling...
[WDS] App hot update...
[HMR] Checking for updates on the server...
XHR finished loading: GET "http://localhost:8080/df32ff4...hot-update.json.
[HMR] Updated modules:
[HMR] - ./src/library/protons/ModalWorkflow/sandbox/workflowStepOne.js
[HMR] - ./src/library/protons/ModalWorkflow/sandbox/index.js
[HMR] - ./src/configs/routes.js
[HRM] - ./src/views/intro/index.js
[HRM] - ./src/view/home/index.js
[HRM] - ./src/app.js
[HRM] App is up to date.

浏览器根本不反映代码更改。 没有错误,没有警告。

尝试了几种不同的方法来检查任何潜在的错误,但是截至目前,我处在这个绝望的地方,不知道我还能尝试什么。

0 个答案:

没有答案