Skip to content

Commit eda4638

Browse files
author
purpleeeee
committed
chunk by lazy import
1 parent 9dffc75 commit eda4638

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

src/client/foundation/App.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { Suspense } from "react";
22
import { BrowserRouter } from "react-router-dom";
33
import { StyleSheetManager } from "styled-components";
44

@@ -13,7 +13,9 @@ export const App = () => {
1313
<AuthContextProvider>
1414
<GlobalStyle />
1515
<BrowserRouter>
16-
<Routes />
16+
<Suspense fallback={<p>loading...</p>}>
17+
<Routes />
18+
</Suspense>
1719
</BrowserRouter>
1820
</AuthContextProvider>
1921
</StyleSheetManager>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./Top";
1+
export { Top as default } from "./Top";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./Odds";
1+
export { Odds as default } from "./Odds";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./RaceCard";
1+
export { RaceCard as default } from "./RaceCard";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./RaceResult";
1+
export { RaceResult as default } from "./RaceResult";

src/client/foundation/routes.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from "react";
1+
import React, { lazy } from "react";
22
import { Route, Routes as RouterRoutes } from "react-router-dom";
33

44
import { CommonLayout } from "./layouts/CommonLayout";
5-
import { Top } from "./pages/Top";
6-
import { Odds } from "./pages/races/Odds";
7-
import { RaceCard } from "./pages/races/RaceCard";
8-
import { RaceResult } from "./pages/races/RaceResult";
5+
6+
const Top = lazy(() => import("./pages/Top"));
7+
const Odds = lazy(() => import("./pages/races/Odds"));
8+
const RaceCard = lazy(() => import("./pages/races/RaceCard"));
9+
const RaceResult = lazy(() => import("./pages/races/RaceResult"));
910

1011
/** @type {React.VFC} */
1112
export const Routes = () => {

webpack.config.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const DIST_PUBLIC = abs("./dist/public");
1818
/** @type {Array<import('webpack').Configuration>} */
1919
module.exports = [
2020
{
21-
// devtool: "inline-source-map",
22-
entry: path.join(SRC_ROOT, "client/index.jsx"),
21+
entry: {
22+
main: path.join(SRC_ROOT, "client/index.jsx"),
23+
},
2324
mode: "production",
2425
module: {
2526
rules: [
@@ -42,8 +43,12 @@ module.exports = [
4243
[
4344
"@babel/preset-env",
4445
{
45-
modules: "cjs",
4646
spec: true,
47+
targets: {
48+
esmodules: true,
49+
},
50+
// modules: "cjs",
51+
// modules: false,
4752
},
4853
],
4954
"@babel/preset-react",
@@ -55,6 +60,7 @@ module.exports = [
5560
},
5661
name: "client",
5762
output: {
63+
chunkFilename: "[name].bundle.js",
5864
path: DIST_PUBLIC,
5965
},
6066
plugins: [

0 commit comments

Comments
 (0)