Skip to content

Commit e28a6f2

Browse files
committed
feat: do code-splitting with react-router
1 parent fb3553e commit e28a6f2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"main": "build/index.html",
55
"unpkg": "build/index.html",
66
"dependencies": {
7+
"@loadable/component": "^5.12.0",
78
"antd": "^3.26.12",
89
"axios": "^0.19.0",
910
"codemirror": "^5.52.2",
@@ -24,6 +25,7 @@
2425
"devDependencies": {
2526
"@types/babel__standalone": "^7.1.2",
2627
"@types/jest": "24.0.15",
28+
"@types/loadable__component": "^5.10.0",
2729
"@types/lodash": "^4.14.149",
2830
"@types/node": "12.0.10",
2931
"@types/react": "16.8.22",

src/AppRouter.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import loadable from '@loadable/component';
12
import React from 'react';
23
import {
34
HashRouter as Router,
5+
Redirect,
46
Route,
57
Switch,
6-
Redirect,
78
} from 'react-router-dom';
8-
import { Gallery } from './gallery';
9-
import { Playground } from './playground';
9+
10+
// react-router code-splitting
11+
// https://reacttraining.com/react-router/web/guides/code-splitting
12+
let Gallery = loadable(async () => {
13+
return (await import('./gallery')).Gallery;
14+
});
15+
let Playground = loadable(async () => {
16+
return (await import('./playground')).Playground;
17+
});
1018

1119
function AppRouter() {
1220
return (

0 commit comments

Comments
 (0)