Skip to content

Commit be8bcbd

Browse files
committed
feat: remove react-loadable instead of react.lazy
1 parent 93970bb commit be8bcbd

4 files changed

Lines changed: 17 additions & 20 deletions

File tree

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "4.0.10",
3+
"version": "4.0.11",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {
@@ -59,7 +59,6 @@
5959
"@types/koa-route": "3.2.4",
6060
"@types/lodash": "4.14.149",
6161
"@types/react-dom": "16.9.4",
62-
"@types/react-loadable": "^5.5.2",
6362
"@types/react-router-dom": "5.1.3",
6463
"@types/rimraf": "2.0.3",
6564
"@types/semver": "6.2.0",
@@ -129,7 +128,6 @@
129128
"react": "16.12.0",
130129
"react-dom": "16.12.0",
131130
"react-hot-loader": "4.12.18",
132-
"react-loadable": "5.5.0",
133131
"react-router-dom": "5.1.2",
134132
"rimraf": "3.0.0",
135133
"sass-loader": "8.0.0",
@@ -152,4 +150,4 @@
152150
"worker-loader": "2.0.0",
153151
"yargs": "15.0.2"
154152
}
155-
}
153+
}

src/built-in-plugins/command-dev/plugin/webpack-dll-config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export default (opts: IOptions) => {
3333
'react-dom',
3434
'lodash',
3535
'highlight.js',
36-
'react-loadable',
3736
'react-router',
3837
'history',
3938
`${PRI_PACKAGE_NAME}/client`,

src/built-in-plugins/project-analyse-pages/plugin/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,21 @@ pri.project.onCreateEntry((analyseInfo: IResult, entry) => {
147147
);
148148
149149
const importCode = `import(/* webpackChunkName: "${
150-
page.chunkName
150+
page.componentName
151151
}" */ "${pageRequirePath}").then(code => {
152152
const filePath = "${path.format(page.file)}"
153153
154154
${await entry.pipe.get('afterPageLoad', '')}
155-
${await entry.pipe.get('returnPageInstance', 'return code.default')}
156-
})`;
155+
${await entry.pipe.get('returnPageInstance', 'return code')}
156+
}),`;
157157
158158
return `
159-
const ${page.componentName} = Loadable<any, any>({
160-
loader: () => ${importCode},
161-
loading: (): any => null
162-
})\n
159+
const ${page.componentName}Lazy: any = React.lazy(() => ${importCode});
160+
const ${page.componentName}: React.FC = props => (
161+
<React.Suspense fallback={PageLazyFallback}>
162+
<${page.componentName}Lazy {...props} />
163+
</React.Suspense>
164+
);
163165
`;
164166
}),
165167
)

src/utils/create-entry.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class Entry {
8686
import { history as customHistory } from "${PRI_PACKAGE_NAME}/client"
8787
import * as React from "react"
8888
import * as ReactDOM from "react-dom"
89-
import * as Loadable from "react-loadable"
9089
import { Redirect, Route, Router, Switch, HashRouter } from "react-router-dom"
9190
`,
9291
);
@@ -97,6 +96,7 @@ export class Entry {
9796
'appBody',
9897
`
9998
export const pageLoadableMap = new Map<string, any>()
99+
const PageLazyFallback = () => <div />;
100100
`,
101101
);
102102
}
@@ -156,8 +156,7 @@ export class Entry {
156156
`
157157
import * as React from "react"
158158
import * as ReactDOM from "react-dom"
159-
import * as Loadable from "react-loadable"
160-
import App, { pageLoadableMap } from "./app"
159+
import App from "./app"
161160
162161
const ROOT_ID = "${pri.sourceConfig.projectRootId}"
163162
`,
@@ -177,12 +176,11 @@ export class Entry {
177176
178177
if ((window as any).enableSsr) {
179178
// Need wait preloadAll, because we already have ssr html.
180-
Loadable.preloadAll().then(() => {
181-
(ReactDOM as any).hydrate(${await pipe.get('entryRenderApp', '<App />')}, document.getElementById(ROOT_ID))
182-
})
179+
// TODO:
180+
// Loadable.preloadAll().then(() => {
181+
// (ReactDOM as any).hydrate(${await pipe.get('entryRenderApp', '<App />')}, document.getElementById(ROOT_ID))
182+
// })
183183
} else {
184-
// Don't need wait preloadAll.
185-
Loadable.preloadAll()
186184
ReactDOM.render(${await pipe.get('entryRenderApp', '<App />')}, document.getElementById(ROOT_ID))
187185
}
188186
`,

0 commit comments

Comments
 (0)