常见问题汇总

React 文件热更新入口配置模板

import React from 'react';
import ReactDom from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import Entry from '${this.resourcePath.replace(/\\/g, '\\\\')}';
const state = window.__INITIAL_STATE__;
const render = (App)=>{
 // 如果是 SSR 渲染时,请用 hydrate, 否则用 render,主要解决警告问题,不影响实际功能
 ReactDom.hydrate(EASY_ENV_IS_DEV ? <AppContainer><App {...state} /></AppContainer> 
    : <App {...state} />, document.getElementById('app'));
};

if (module.hot) {
  module.hot.accept('${this.resourcePath.replace(/\\/g, '\\\\')}', () => { render(Entry); });
}
render(Entry);

热更新 HMR 生效,但页面没有更新

if (module.hot) {
  module.hot.accept('${this.resourcePath.replace(/\\/g, '\\\\')}', () => { render(Entry); });
}

改成

if (module.hot) {
  module.hot.accept();
}

更多常见问题

https://github.com/easy-team/egg-react-webpack-boilerplate/issues


Author: sky
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source sky !
 Previous
Weex 工程方案 Weex 工程方案
easywebpack-weex 基于 easywebpack 的 Weex Native 和 Weex Web 打包构建解决方案.安装$ npm i easywebpack-weex --save-dev使用const weex = require('easywebpack-weex'); ...
2019-12-23 sky
Next 
AntD 配置 AntD 配置
项目示例: https://github.com/easy-team/egg-react-webpack-boilerplate/tree/antd-theme按需加载依赖配置
2019-12-23 sky