Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ssr #2543

Merged
merged 46 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2d13e22
simply alias config
sorrycc Jun 4, 2019
c868e40
fix files lost
sorrycc Jun 4, 2019
5a4f3d4
Merge branch 'master' into feat/ssr
sorrycc Jun 4, 2019
f85108f
build extra ssr bundle
sorrycc Jun 4, 2019
1b253d0
implement ssr
sorrycc Jun 4, 2019
8f4c263
fix Invariant Violation
sorrycc Jun 4, 2019
4f20873
render html automatically
sorrycc Jun 5, 2019
327efc6
data flow
sorrycc Jun 5, 2019
a0d4592
fix memory history's pathname
sorrycc Jun 5, 2019
daf4ca7
run getInitialProps if need
sorrycc Jun 5, 2019
55024f8
code style
sorrycc Jun 6, 2019
40b8c55
fix ci
sorrycc Jun 6, 2019
451414c
fix ci again
sorrycc Jun 6, 2019
dd30e75
fix redundent getInitialProps execute
sorrycc Jun 6, 2019
d267e38
extract findRoute and add testcases
sorrycc Jun 6, 2019
96a70f8
normalize data for g_initialData
sorrycc Jun 6, 2019
cf4db43
support dva
sorrycc Jun 6, 2019
ad2555a
fix unexpect getInitialProps call
sorrycc Jun 6, 2019
0a4c595
fix history undefined when config.disableGlobalVaribles is set
sorrycc Jun 6, 2019
33cac87
fix findRoutes, Close #2552
sorrycc Jun 8, 2019
43f6f2d
fix: umi external bug (#2560)
ycjcl868 Jun 10, 2019
016a295
support multiple template
sorrycc Jun 10, 2019
26d62b9
export htmlElement and rootContainer
sorrycc Jun 10, 2019
051a2cc
Merge commit '4b0e0b12a64aacf04a4d365e151bf67dfe1802c0' into feat/ssr
sorrycc Jun 10, 2019
ab54474
Merge origin/master into feat/ssr
ycjcl868 Jun 10, 2019
460829b
fix: 修复 history createMemoryHistory 报错 (#2572)
ycjcl868 Jun 11, 2019
357e079
Fix ssr hd (#2571)
ycjcl868 Jun 11, 2019
2b81fb1
fix: 修复 ssr 下 css 文件重复 build 的问题 (#2582)
ycjcl868 Jun 12, 2019
ee136bd
feat: ssr 支持 dynamicImport (#2584)
ycjcl868 Jun 12, 2019
542d952
feat: pre render plugin (#2592)
ycjcl868 Jun 13, 2019
90bd189
Merge master into feat/ssr
ycjcl868 Jun 14, 2019
bf6633e
fix: locale 插件兼容 ssr,抛出 umi.server.js 错误 (#2602)
ycjcl868 Jun 15, 2019
f7b4b6d
:memo: ssr doc (#2607)
ycjcl868 Jun 15, 2019
539f4c5
tweak ssr warning (#2609)
ycjcl868 Jun 15, 2019
e9d51b9
Merge master into feat/ssr
ycjcl868 Jun 15, 2019
ae7d7b6
Merge origin/master into feat/ssr
ycjcl868 Jun 17, 2019
0f8e027
Fix chunk map (#2616)
ycjcl868 Jun 17, 2019
e1c0c15
Merge origin/master into feat/ssr
ycjcl868 Jun 17, 2019
e703cb5
Merge origin/master into feat/ssr
ycjcl868 Jun 18, 2019
c9dd799
fix: yarn.lock
ycjcl868 Jun 18, 2019
ac9f6d9
Merge origin/master into feat/ssr
ycjcl868 Jun 18, 2019
dcd614a
upd: yarn lock
ycjcl868 Jun 18, 2019
7399386
Test cases ssr (#2631)
Jun 18, 2019
3b92ae7
Merge master into feat/ssr
Jun 19, 2019
aba6d82
fix: prerender not render dynamic routing (#2636)
Jun 19, 2019
fac5b6d
Fix prerender bug (#2644)
Jun 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package-lock.json
/packages/**/.docz
/packages/*/lib
/packages/*/dist
/packages/af-webpack/test/bundlestats.json

dist
coverage
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = {
{
title: '官方插件',
collapsable: false,
children: ['umi-plugin-react'],
children: ['umi-plugin-react', 'umi-plugin-prerender'],
},
{
title: '插件开发',
Expand Down
163 changes: 95 additions & 68 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ sidebarDepth: 2

### plugins

* Type: `Array`
* Default: `[]`
- Type: `Array`
- Default: `[]`

Specify the plugins.

Expand All @@ -34,19 +34,22 @@ If the plugin has parameters, it is configured as an array. The first item is th
export default {
plugins: [
// 有参数
['umi-plugin-react', {
dva: true,
antd: true,
}],
[
'umi-plugin-react',
{
dva: true,
antd: true,
},
],
'./plugin',
],
};
```

### routes

* Type: `Array`
* Default: `null`
- Type: `Array`
- Default: `null`

Configure routing.

Expand Down Expand Up @@ -74,8 +77,8 @@ Notice:

### disableRedirectHoist

* Type:`Boolean`
* Default: `false`
- Type:`Boolean`
- Default: `false`

For some reason, we hoist all redirect when parsing the route config, but this caused some problems, so add this configuration to disable redirect hoist.

Expand All @@ -87,8 +90,8 @@ export default {

### history

* Type: `String | [String, Object]`
* Default: `browser`
- Type: `String | [String, Object]`
- Default: `browser`

Specify the history type, including `browser`, `hash` and `memory`.

Expand All @@ -102,65 +105,65 @@ export default {

### outputPath

* Type: `String`
* Default: `./dist`
- Type: `String`
- Default: `./dist`

Specifies the output path.

### base

* Type: `String`
* Default: `/`
- Type: `String`
- Default: `/`

Specify the base of the react-router to be configured when deploying to a non-root directory.

### publicPath

* Type: `String`
* Default: `/`
- Type: `String`
- Default: `/`

Specifies the publicPath of the webpack, pointing to the path where the static resource file is located.

### runtimePublicPath

* Type: `Boolean`
* Default: `false`
- Type: `Boolean`
- Default: `false`

Use the `window.publicPath` specified in the HTML when the value is `true`.

### cssPublicPath <Badge text="2.2.5+"/>

* Type: `String`
* Default: same as `publicPath`
- Type: `String`
- Default: same as `publicPath`

Specify an extra publicPath for CSS.

### mountElementId

* Type: `String`
* Default: `root`
- Type: `String`
- Default: `root`

Specifies the mount point id which the react app will mount to.

### minimizer

* Type: `String`
* Default: `uglifyjs`
* Options: `uglifyjs|terserjs`
- Type: `String`
- Default: `uglifyjs`
- Options: `uglifyjs|terserjs`

Which minimizer to use. UglifyJS does not support es6 while [terser](https://github.com/terser-js/terser) does.

### hash

* Type: `Boolean`
* Default: `false`
- Type: `Boolean`
- Default: `false`

Whether to enable the hash file suffix.

### targets <Badge text="2.1.0+"/>

* Type: `Object`
* Default: `{ chrome: 49, firefox: 45, safari: 10, edge: 13, ios: 10 }`
- Type: `Object`
- Default: `{ chrome: 49, firefox: 45, safari: 10, edge: 13, ios: 10 }`

Configuring the minimum version of browsers you want to compatible with, umi will automatically introduce polyfill and transform grammar. Configuration items will be merged to default values, so there is no need to give any duplicate configuration.

Expand All @@ -176,15 +179,15 @@ export default {

### context

* Type: `Object`
* Default: `{}`
- Type: `Object`
- Default: `{}`

Configuring a global context will override the context in each page.

### exportStatic

* Type: `Boolean | Object`
* Default: `false`
- Type: `Boolean | Object`
- Default: `false`

If set to `true` or `Object`, all routes are exported as static pages, otherwise only one index.html is output by default.

Expand All @@ -196,28 +199,28 @@ such as:

### exportStatic.htmlSuffix

* Type: `Boolean`
* Default: `false`
- Type: `Boolean`
- Default: `false`

Enable the `.html` suffix.

### exportStatic.dynamicRoot

* Type: `Boolean`
* Default: `false`
- Type: `Boolean`
- Default: `false`

Deploy to any path.

### singular

* Type: `Boolean`
* Default: `false`
- Type: `Boolean`
- Default: `false`

If set to `true`, enable the directory for singular mode.

* src/layout/index.js
* src/page
* model (if umi-plugin-dva plugin is enabled)
- src/layout/index.js
- src/page
- model (if umi-plugin-dva plugin is enabled)

### mock.exclude <Badge text="2.4.5+"/>

Expand All @@ -231,12 +234,9 @@ e.g. exclue all files and directorys starts with `_`,
```js
export default {
mock: {
exclude: [
'mock/**/_*.js',
'mock/_*/**/*.js',
],
}
}
exclude: ['mock/**/_*.js', 'mock/_*/**/*.js'],
},
};
```

### block <Badge text="2.7.0+"/>
Expand All @@ -247,12 +247,46 @@ export default {
```js
export default {
block: {
defaultGitUrl: "https://github.com/ant-design/pro-blocks",
npmClient: "cnpm",
}
defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
npmClient: 'cnpm',
},
};
```

### ssr <Badge text="beta" type="warn"/> <Badge text="2.8.0+"/>

- Type: `Boolean | Object`
- Default: `false`

Configure whether to enable Server-Side Render, which is off by default.

When enabled, `umi.server.js` file is also generated when the client static file is generated. Use the following in Node.js:

```js
// Return the rendered html fragment according to the ctx.req.url
async function UmiServerRender(ctx) {
// mock a window object
global.window = {};
// require module
const serverRender = require('./dist/umi.server');
// export react-dom/server to avoid React hooks ssr error
const { ReactDOMServer } = serverRender;

const {
// Current root container element
rootContainer,
// Document html Element = rootContainer + template Element
htmlElement,
} = await serverRender.default(ctx);

// Render the element into html
const ssrHtml = ReactDOMServer.renderToString(htmlElement);
return ssrHtml;
}
```

[using Pre-Rendering](/plugin/umi-plugin-prerender.html), [umi-example-ssr-with-egg](https://github.com/umijs/umi-example-ssr-with-egg)

## webpack

### chainWebpack
Expand All @@ -270,10 +304,10 @@ chainWebpack(config, { webpack }) {
config.plugins.delete('progress');
}
```

### theme

The configuration theme is actually equipped with the less variable. Support for both object and string types, the string needs to point to a file that returns the configuration.
such as:
The configuration theme is actually equipped with the less variable. Support for both object and string types, the string needs to point to a file that returns the configuration. such as:

```
"theme": {
Expand Down Expand Up @@ -306,8 +340,7 @@ For example, after [ant-design-pro opens tree-shaking](https://github.com/ant-de

### define

Passed to the code via the webpack's DefinePlugin , the value is automatically handled by `JSON.stringify`.
such as:
Passed to the code via the webpack's DefinePlugin , the value is automatically handled by `JSON.stringify`. such as:

```js
"define": {
Expand All @@ -318,8 +351,7 @@ such as:

### externals

Configure the [externals](https://webpack.js.org/configuration/externals/) property of webpack.
such as:
Configure the [externals](https://webpack.js.org/configuration/externals/) property of webpack. such as:

```js
// Configure react and react-dom do not enter the code
Expand Down Expand Up @@ -385,7 +417,7 @@ const config = {
mediaQuery: false,
}),
],
}
};
```

### cssModulesExcludes
Expand All @@ -409,8 +441,7 @@ such as:

### proxy

Configure the [proxy](https://webpack.js.org/configuration/dev-server/#devserver-proxy) property of webpack-dev-server.
If you want to proxy requests to other servers, you can do this:
Configure the [proxy](https://webpack.js.org/configuration/dev-server/#devserver-proxy) property of webpack-dev-server. If you want to proxy requests to other servers, you can do this:

```markup
"proxy": {
Expand All @@ -430,8 +461,7 @@ Configure options for [node-sass](https://github.com/sass/node-sass#options). No

### manifest

After configuration, asset-manifest.json will be generated and the option will be passed to [https://www.npmjs.com/package/webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin).
such as:
After configuration, asset-manifest.json will be generated and the option will be passed to [https://www.npmjs.com/package/webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin). such as:

```markup
"manifest": {
Expand Down Expand Up @@ -500,9 +530,6 @@ e.g.

```js
export default {
browserslist: [
'> 1%',
'last 2 versions',
],
browserslist: ['> 1%', 'last 2 versions'],
};
```
Loading