umi.tpl
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{{{ polyfillImports }}}
{{{ importsAhead }}}
import { plugin } from './core/plugin';
import './core/pluginRegister';
{{#enableHistory}}
import { createHistory } from './core/history';
{{/enableHistory}}
import { ApplyPluginsType } from '{{{ runtimePath }}}';
import { renderClient } from '{{{ rendererPath }}}';
import { getRoutes } from './core/routes';
{{{ imports }}}
{{{ entryCodeAhead }}}
const getClientRender = (args: { hot?: boolean; routes?: any[] } = {}) => plugin.applyPlugins({
key: 'render',
type: ApplyPluginsType.compose,
initialValue: () => {
const opts = plugin.applyPlugins({
key: 'modifyClientRenderOpts',
type: ApplyPluginsType.modify,
initialValue: {
routes: args.routes || getRoutes(),
plugin,
{{#enableHistory}}
history: createHistory(args.hot),
{{/enableHistory}}
isServer: process.env.__IS_SERVER,
{{#enableSSR}}
ssrProps: {},
{{/enableSSR}}
{{#dynamicImport}}
dynamicImport: {{{ dynamicImport }}},
{{/dynamicImport}}
rootElement: '{{{ rootElement }}}',
{{#enableTitle}}
defaultTitle: `{{{ defaultTitle }}}`,
{{/enableTitle}}
},
});
return renderClient(opts);
},
args,
});
const clientRender = getClientRender();
export default clientRender();
{{{ entryCode }}}
// hot module replacement
// @ts-ignore
if (module.hot) {
// @ts-ignore
module.hot.accept('./core/routes', () => {
const ret = require('./core/routes');
if (ret.then) {
ret.then(({ getRoutes }) => {
getClientRender({ hot: true, routes: getRoutes() })();
});
} else {
getClientRender({ hot: true, routes: ret.getRoutes() })();
}
});
}