zoukankan      html  css  js  c++  java
  • react项目打包优化

    优化前:

    优化中:

    优化完成:

     

    要点:

    1.路由懒加载

    2.在路由懒加载前把自己开发的公共组件全部引入

    3.剔除掉比较大的公共组件(例如富文本组件),在业务页面中单独引入

    import React, { Suspense, lazy } from 'react'
    import { Switch, Route, Redirect, useHistory } from 'react-router-dom'
    import Loading from '../components/light/Loading'
    //自己开发的公共组件会再此处全部引入
    import { ErrorBoundary } from '../components/light'
    const Login = lazy(() => import('../views/light/login/Login'))
    const SaleLogin = lazy(() => import('../views/sale/login/Login'))
    const EduLogin = lazy(() => import('../views/edu/login/Login'))
    const Index = lazy(() => import('../views/light/index/Index'))
    const NotFound = lazy(() => import('../views/light/notFound/NotFound'))
    
    export default function Router() {
      window.reactRouter = useHistory()
      return (
        <>
          <ErrorBoundary>
            <Suspense fallback={<Loading isLazyLoading={true}></Loading>}>
              <Switch>
                <Redirect from="/" to="/light/login" exact></Redirect>
                <Route path="/light/login" component={Login}></Route>
                <Route path="/sale/login" component={SaleLogin}></Route>
                <Route path="/edu/login" component={EduLogin}></Route>
                <Route path="/light/index" component={Index}></Route>
                <Route path="/sale/index" component={Index}></Route>
                <Route path="/edu/index" component={Index}></Route>
                <Route path="/404" component={NotFound}></Route>
                <Redirect from="*" to="/404" exact></Redirect>
              </Switch>
            </Suspense>
          </ErrorBoundary>
          <Loading></Loading>
        </>
      )
    }
    
  • 相关阅读:
    连接多台机子的多个数据库webconfig
    md5
    JavaScript substring() 方法
    Coolite ComboBox 模糊查询
    2010暴强语录
    Response.ContentType 说明
    C#得到磁盘信息
    Coolite Toolkit 1.0版本在线demo
    关于IT人职业道德的反思(转)
    Coolite TextField添加回车事件
  • 原文地址:https://www.cnblogs.com/xutongbao/p/15264310.html
Copyright © 2011-2022 走看看