issue: react-loadable 怎么加入这个骨架中 #23

安装依赖

npm install react-loadable --save

实现异步组件

// async-image.jsx
import React, { Component } from 'react';
import Logo from '../../../../asset/images/react.png';
export default class AsyncImage extends React.Component {
    render() {
        return <div><img src={Logo} /><div>这是异步加载的内容</div></div>
    }
}

// loading.jsx    
import React, { Component } from 'react';
export default class Loading extends React.Component {
    render() {
        return <div>Loading.....</div>
    }
}

引入异步组件

import React, { Component } from 'react';
import Loadable from 'react-loadable';
import Loading from './widget/loading';

const AsyncImageLoadableComponent = Loadable({
  loader: () => import('./widget/async-image'),
  loading: Loading,
});

export default class About extends Component {

  render() {
    return <div>
      <h3 className="spa-title">Egg + React + Redux + React Router SPA Server Side + Webpack Render Example</h3>
      <div style={{ 'text-align': 'center' }}><AsyncImageLoadableComponent /></div>
    </div>;
  }
}

本地开发模式异步模块找不到问题

image.png

解决方案:easywebpack 在开发模式构建时,筛选出异步chunk 模块,然后落地磁盘


具体例子见:https://github.com/easy-team/egg-react-webpack-boilerplate/blob/dynamic-import/app/web/page/app/components/router/about.jsx


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
AntD 配置 AntD 配置
项目示例: https://github.com/easy-team/egg-react-webpack-boilerplate/tree/antd-theme按需加载依赖配置
2019-12-23 sky
Next 
asset 前端渲染 asset 前端渲染
背景在 前端渲染模式 章节讲到了基于 React 的一体化的前端渲染模式,好处是不需要借助第三方模板引擎且无效关注静态资源注入问题,但有两个小的功能限制:layout 模板数据绑定能力较弱资源注入不能自己定义,比如 async, crossorigin 等配置针对上面问题 egg-view-r...
2019-12-23 sky