Skip to content

Commit 4c53eb9

Browse files
committed
fix: enable code spliting for app
1 parent b4b8593 commit 4c53eb9

File tree

12 files changed

+65
-246
lines changed

12 files changed

+65
-246
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ README.md
66
ROADMAP.md
77
build
88
.env
9-
data.db
9+
data.db
10+
app/node_modules

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ VERSION := $(or $(VERSION),$(DEFAULT_VERSION))
33

44
cmd:
55
cd server && go build -ldflags "-w -X main.VERSION=$(VERSION)" -o '../build/server'
6+
build-app:
7+
cd app && npm i && npm run build
68
clean:
79
rm -rf build
810
test:

app/build/bundle.css

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/build/bundle.js

Lines changed: 0 additions & 195 deletions
This file was deleted.

app/build/bundle.js.map

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/esbuild.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const __is_prod__ = process.env.NODE_ENV === 'production';
2+
require('esbuild').build({
3+
entryPoints: ['src/index.tsx'],
4+
chunkNames: '[name]-[hash]',
5+
bundle: true,
6+
minify: __is_prod__,
7+
outdir: 'build',
8+
splitting: true,
9+
format: 'esm',
10+
watch: !__is_prod__,
11+
});

app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "esbuild src/index.tsx --bundle --minify --sourcemap --outfile=build/bundle.js"
7+
"build": "rm -rf build && NODE_ENV=production node ./esbuild.config.js",
8+
"start": "NODE_ENV=development node ./esbuild.config.js"
89
},
910
"keywords": [],
1011
"author": "Lakhan Samani",

app/src/Root.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, lazy, Suspense } from 'react';
22
import { Switch, Route } from 'react-router-dom';
33
import { useAuthorizer } from '@authorizerdev/authorizer-react';
4-
import Dashboard from './pages/dashboard';
5-
import Login from './pages/login';
6-
import ResetPassword from './pages/rest-password';
4+
5+
const ResetPassword = lazy(() => import('./pages/rest-password'));
6+
const Login = lazy(() => import('./pages/login'));
7+
const Dashboard = lazy(() => import('./pages/dashboard'));
78

89
export default function Root() {
910
const { token, loading, config } = useAuthorizer();
@@ -24,22 +25,26 @@ export default function Root() {
2425

2526
if (token) {
2627
return (
27-
<Switch>
28-
<Route path="/app" exact>
29-
<Dashboard />
30-
</Route>
31-
</Switch>
28+
<Suspense fallback={<></>}>
29+
<Switch>
30+
<Route path="/app" exact>
31+
<Dashboard />
32+
</Route>
33+
</Switch>
34+
</Suspense>
3235
);
3336
}
3437

3538
return (
36-
<Switch>
37-
<Route path="/app" exact>
38-
<Login />
39-
</Route>
40-
<Route path="/app/reset-password">
41-
<ResetPassword />
42-
</Route>
43-
</Switch>
39+
<Suspense fallback={<></>}>
40+
<Switch>
41+
<Route path="/app" exact>
42+
<Login />
43+
</Route>
44+
<Route path="/app/reset-password">
45+
<ResetPassword />
46+
</Route>
47+
</Switch>
48+
</Suspense>
4449
);
4550
}

app/src/index.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
color: #374151;
9+
font-size: 14px;
10+
}
11+
12+
*,
13+
*:before,
14+
*:after {
15+
box-sizing: inherit;
16+
}

app/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './App';
4+
import './index.css';
45

56
ReactDOM.render(<App />, document.getElementById('root'));

0 commit comments

Comments
 (0)