一.生产环境优化(去除redux中间件)
在store/index.js中
let middlewares
if (process.env.NODE_ENV === 'production') {
// 生产环境,只启用 thunk 中间件
middlewares = applyMiddleware(thunk)
} else {
middlewares = composeWithDevTools(applyMiddleware(thunk))
}
二.路由懒加载
import { lazy, Suspense } from 'react'
// 导入页面组件
const Login = lazy(() => import('./pages/Login'))
const Layout = lazy(() => import('./pages/Layout'))
const App = () => {
return (
<Router history={history}>
<Suspense
fallback={
<div
style={
{
textAlign: 'center',
marginTop: 200
}}
>
loading...
</div>
}
>
<div className="app">
&