Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
5962c6d0
Unverified
Commit
5962c6d0
authored
Feb 26, 2025
by
nbb
Committed by
GitHub
Feb 26, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: optimize initial load performance by implementing lazy loading and code splitting (#4445)
parent
bef67638
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
32 deletions
+112
-32
index.tsx
web/src/router/index.tsx
+98
-31
vite.config.ts
web/vite.config.ts
+14
-1
No files found.
web/src/router/index.tsx
View file @
5962c6d0
import
{
Suspense
,
lazy
}
from
"react"
;
import
{
createBrowserRouter
}
from
"react-router-dom"
;
import
{
createBrowserRouter
}
from
"react-router-dom"
;
import
App
from
"@/App"
;
import
App
from
"@/App"
;
import
HomeLayout
from
"@/layouts/HomeLayout"
;
import
HomeLayout
from
"@/layouts/HomeLayout"
;
import
RootLayout
from
"@/layouts/RootLayout"
;
import
RootLayout
from
"@/layouts/RootLayout"
;
import
About
from
"@/pages/About"
;
import
AdminSignIn
from
"@/pages/AdminSignIn"
;
import
Archived
from
"@/pages/Archived"
;
import
AuthCallback
from
"@/pages/AuthCallback"
;
import
Explore
from
"@/pages/Explore"
;
import
Home
from
"@/pages/Home"
;
import
Home
from
"@/pages/Home"
;
import
Inboxes
from
"@/pages/Inboxes"
;
import
Loading
from
"@/pages/Loading"
;
import
MemoDetail
from
"@/pages/MemoDetail"
;
import
NotFound
from
"@/pages/NotFound"
;
const
About
=
lazy
(()
=>
import
(
"@/pages/About"
));
import
PermissionDenied
from
"@/pages/PermissionDenied"
;
const
AdminSignIn
=
lazy
(()
=>
import
(
"@/pages/AdminSignIn"
));
import
Resources
from
"@/pages/Resources"
;
const
Archived
=
lazy
(()
=>
import
(
"@/pages/Archived"
));
import
Setting
from
"@/pages/Setting"
;
const
AuthCallback
=
lazy
(()
=>
import
(
"@/pages/AuthCallback"
));
import
SignIn
from
"@/pages/SignIn"
;
const
Explore
=
lazy
(()
=>
import
(
"@/pages/Explore"
));
import
SignUp
from
"@/pages/SignUp"
;
const
Inboxes
=
lazy
(()
=>
import
(
"@/pages/Inboxes"
));
import
UserProfile
from
"@/pages/UserProfile"
;
const
MemoDetail
=
lazy
(()
=>
import
(
"@/pages/MemoDetail"
));
import
MemoDetailRedirect
from
"./MemoDetailRedirect"
;
const
NotFound
=
lazy
(()
=>
import
(
"@/pages/NotFound"
));
const
PermissionDenied
=
lazy
(()
=>
import
(
"@/pages/PermissionDenied"
));
const
Resources
=
lazy
(()
=>
import
(
"@/pages/Resources"
));
const
Setting
=
lazy
(()
=>
import
(
"@/pages/Setting"
));
const
SignIn
=
lazy
(()
=>
import
(
"@/pages/SignIn"
));
const
SignUp
=
lazy
(()
=>
import
(
"@/pages/SignUp"
));
const
UserProfile
=
lazy
(()
=>
import
(
"@/pages/UserProfile"
));
const
MemoDetailRedirect
=
lazy
(()
=>
import
(
"./MemoDetailRedirect"
));
export
enum
Routes
{
export
enum
Routes
{
ROOT
=
"/"
,
ROOT
=
"/"
,
...
@@ -40,19 +43,35 @@ const router = createBrowserRouter([
...
@@ -40,19 +43,35 @@ const router = createBrowserRouter([
children
:
[
children
:
[
{
{
path
:
""
,
path
:
""
,
element
:
<
SignIn
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
SignIn
/>
</
Suspense
>
),
},
},
{
{
path
:
"admin"
,
path
:
"admin"
,
element
:
<
AdminSignIn
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
AdminSignIn
/>
</
Suspense
>
),
},
},
{
{
path
:
"signup"
,
path
:
"signup"
,
element
:
<
SignUp
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
SignUp
/>
</
Suspense
>
),
},
},
{
{
path
:
"callback"
,
path
:
"callback"
,
element
:
<
AuthCallback
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
AuthCallback
/>
</
Suspense
>
),
},
},
],
],
},
},
...
@@ -69,54 +88,102 @@ const router = createBrowserRouter([
...
@@ -69,54 +88,102 @@ const router = createBrowserRouter([
},
},
{
{
path
:
Routes
.
EXPLORE
,
path
:
Routes
.
EXPLORE
,
element
:
<
Explore
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
Explore
/>
</
Suspense
>
),
},
},
{
{
path
:
Routes
.
ARCHIVED
,
path
:
Routes
.
ARCHIVED
,
element
:
<
Archived
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
Archived
/>
</
Suspense
>
),
},
},
{
{
path
:
"u/:username"
,
path
:
"u/:username"
,
element
:
<
UserProfile
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
UserProfile
/>
</
Suspense
>
),
},
},
],
],
},
},
{
{
path
:
Routes
.
RESOURCES
,
path
:
Routes
.
RESOURCES
,
element
:
<
Resources
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
Resources
/>
</
Suspense
>
),
},
},
{
{
path
:
Routes
.
INBOX
,
path
:
Routes
.
INBOX
,
element
:
<
Inboxes
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
Inboxes
/>
</
Suspense
>
),
},
},
{
{
path
:
Routes
.
SETTING
,
path
:
Routes
.
SETTING
,
element
:
<
Setting
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
Setting
/>
</
Suspense
>
),
},
},
{
{
path
:
"memos/:uid"
,
path
:
"memos/:uid"
,
element
:
<
MemoDetail
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
MemoDetail
/>
</
Suspense
>
),
},
},
{
{
path
:
Routes
.
ABOUT
,
path
:
Routes
.
ABOUT
,
element
:
<
About
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
About
/>
</
Suspense
>
),
},
},
// Redirect old path to new path.
// Redirect old path to new path.
{
{
path
:
"m/:uid"
,
path
:
"m/:uid"
,
element
:
<
MemoDetailRedirect
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
MemoDetailRedirect
/>
</
Suspense
>
),
},
},
{
{
path
:
"403"
,
path
:
"403"
,
element
:
<
PermissionDenied
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
PermissionDenied
/>
</
Suspense
>
),
},
},
{
{
path
:
"404"
,
path
:
"404"
,
element
:
<
NotFound
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
NotFound
/>
</
Suspense
>
),
},
},
{
{
path
:
"*"
,
path
:
"*"
,
element
:
<
NotFound
/>,
element
:
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
NotFound
/>
</
Suspense
>
),
},
},
],
],
},
},
...
...
web/vite.config.ts
View file @
5962c6d0
...
@@ -44,8 +44,21 @@ export default defineConfig({
...
@@ -44,8 +44,21 @@ export default defineConfig({
rollupOptions
:
{
rollupOptions
:
{
output
:
{
output
:
{
entryFileNames
:
"app.[hash].js"
,
entryFileNames
:
"app.[hash].js"
,
chunkFileNames
:
"assets/chunk-vendors.[hash].js"
,
chunkFileNames
:
(
chunkInfo
)
=>
{
const
facadeModuleId
=
chunkInfo
.
facadeModuleId
?
chunkInfo
.
facadeModuleId
.
split
(
"/"
)
:
[];
const
name
=
facadeModuleId
[
facadeModuleId
.
length
-
2
]
||
"[name]"
;
return
`assets/
${
name
}
/[name].[hash].js`
;
},
assetFileNames
:
"assets/[name].[hash][extname]"
,
assetFileNames
:
"assets/[name].[hash][extname]"
,
manualChunks
:
{
"react-vendor"
:
[
"react"
,
"react-dom"
,
"react-router-dom"
],
"mui-vendor"
:
[
"@mui/joy"
,
"@emotion/react"
,
"@emotion/styled"
],
"utils-vendor"
:
[
"dayjs"
,
"lodash-es"
,
"mobx"
,
"mobx-react-lite"
],
"katex-vendor"
:
[
"katex"
],
"highlight-vendor"
:
[
"highlight.js"
],
"mermaid-vendor"
:
[
"mermaid"
],
"map-vendor"
:
[
"leaflet"
,
"react-leaflet"
],
},
},
},
},
},
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment