Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit a594624

Browse files
committed
feat: 完善ssr-with-loadable
1 parent 9a78a8f commit a594624

File tree

8 files changed

+13
-9
lines changed

8 files changed

+13
-9
lines changed

docs/guide/ssr-csr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const dev = () => {
7777

7878
``` js
7979
const commonNode = props => (
80-
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? { props.children } : ''
80+
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? <div>{ props.children }</div> : ''
8181
// 作为承载csr应用页面模版时,我们只需要返回一个空的节点
8282
props.children ? <div className='normal'><h1 className='title'><Link to='/'>Egg + React + SSR</Link><div className='author'>by ykfe</div></h1>{props.children}</div>
8383
: ''

docs/guide/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { Link } from 'react-router-dom'
6868
import serialize from 'serialize-javascript'
6969

7070
const commonNode = props => (
71-
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? { props.children } : ''
71+
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? <div>{ props.children }</div> : ''
7272
props.children ? <div className='normal'><h1 className='title'><Link to='/'>Egg + React + SSR</Link><div className='author'>by ykfe</div></h1>{props.children}</div>
7373
: ''
7474
)

example/ssr-with-antd/web/layout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
66
import serialize from 'serialize-javascript'
77

88
const commonNode = props => (
9-
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? { props.children } : ''
9+
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? <div>{ props.children }</div> : ''
1010
props.children ? <div className='normal'><h1 className='title'><Link to='/'>Egg + React + SSR</Link><div className='author'>by ykfe</div></h1>{props.children}</div>
1111
: ''
1212
)

example/ssr-with-dva/web/layout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
66
import serialize from 'serialize-javascript'
77

88
const commonNode = props => (
9-
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? { props.children } : ''
9+
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? <div>{ props.children }</div> : ''
1010
props.children ? <div className='normal'><h1 className='title'><Link to='/'>Egg + React + SSR</Link><div className='author'>by ykfe</div></h1>{props.children}</div>
1111
: ''
1212
)

example/ssr-with-js/web/layout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '@/assets/common.less'
66
import './index.less'
77

88
const commonNode = props => (
9-
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? { props.children } : ''
9+
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? <div>{ props.children }</div> : ''
1010
props.children
1111
? <div className='normal'><h1 className='title'><Link to='/'>Egg + React + SSR</Link><div className='author'>by ykfe</div></h1>{props.children}</div>
1212
: ''

example/ssr-with-loadable/build/webpack.config.client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
const path = require('path')
33
const webpack = require('webpack')
44
const merge = require('webpack-merge')
5-
const baseConfig = require('./webpack.config.base')
65
const TerserPlugin = require('terser-webpack-plugin')
76
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
8-
const paths = require('./paths')
97
const ManifestPlugin = require('webpack-manifest-plugin')
108
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin')
119
const safePostCssParser = require('postcss-safe-parser')
1210
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
11+
const baseConfig = require('./webpack.config.base')
12+
const paths = require('./paths')
1313
const publicPath = '/'
1414
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'
1515
const isDev = process.env.NODE_ENV === 'development'

example/ssr-with-loadable/web/layout/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const Layout = (props) => {
1515
if (__isBrowser__) {
1616
return commonNode(props)
1717
} else {
18-
const { serverData } = props.layoutData
18+
const { serverData, req } = props.layoutData
1919
const { injectCss, injectScript } = props.layoutData.app.config
20+
const chunkName = req ? req.url.split('/')[1] : ''
2021
return (
2122
<html lang='en'>
2223
<head>
@@ -27,6 +28,9 @@ const Layout = (props) => {
2728
{
2829
injectCss && injectCss.map(item => <link rel='stylesheet' href={item} key={item} />)
2930
}
31+
{
32+
(chunkName && chunkName) ? <link rel='stylesheet' href={`/static/css/${chunkName}.chunk.css`} /> : ''
33+
}
3034
</head>
3135
<body>
3236
<div id='app'>{ commonNode(props) }</div>

example/ssr-with-mobx/web/layout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
66
import serialize from 'serialize-javascript'
77

88
const commonNode = props => (
9-
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? { props.children } : ''
9+
// 为了同时兼容ssr/csr请保留此判断,如果你的layout没有内容请使用 props.children ? <div>{ props.children }</div> : ''
1010
props.children ? <div className='normal'><h1 className='title'><Link to='/'>Egg + React + SSR</Link><div className='author'>by ykfe</div></h1>{props.children}</div>
1111
: ''
1212
)

0 commit comments

Comments
 (0)