Skip to content

Commit 889f77b

Browse files
Enrique Moreno Canochuwik
authored andcommitted
Frontend basic code splitting
1 parent 0cc155b commit 889f77b

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

app/frontend/src/index.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
import React from "react";
22
import ReactDOM from "react-dom/client";
3-
import { HashRouter, Routes, Route } from "react-router-dom";
3+
import { createHashRouter, RouterProvider } from "react-router-dom";
44
import { initializeIcons } from "@fluentui/react";
55

66
import "./index.css";
77

88
import Layout from "./pages/layout/Layout";
9-
import NoPage from "./pages/NoPage";
10-
import OneShot from "./pages/oneshot/OneShot";
119
import Chat from "./pages/chat/Chat";
1210

1311
initializeIcons();
1412

15-
export default function App() {
16-
return (
17-
<HashRouter>
18-
<Routes>
19-
<Route path="/" element={<Layout />}>
20-
<Route index element={<Chat />} />
21-
<Route path="qa" element={<OneShot />} />
22-
<Route path="*" element={<NoPage />} />
23-
</Route>
24-
</Routes>
25-
</HashRouter>
26-
);
27-
}
13+
const router = createHashRouter([
14+
{
15+
path: "/",
16+
element: <Layout />,
17+
children: [
18+
{
19+
index: true,
20+
element: <Chat />
21+
},
22+
{
23+
path: "qa",
24+
lazy: () => import("./pages/oneshot/OneShot")
25+
},
26+
{
27+
path: "*",
28+
lazy: () => import("./pages/NoPage")
29+
}
30+
]
31+
}
32+
]);
2833

2934
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
3035
<React.StrictMode>
31-
<App />
36+
<RouterProvider router={router} />
3237
</React.StrictMode>
3338
);

app/frontend/src/pages/NoPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const NoPage = () => {
1+
export function Component(): JSX.Element {
22
return <h1>404</h1>;
3-
};
3+
}
44

5-
export default NoPage;
5+
Component.displayName = "NoPage";

app/frontend/src/pages/oneshot/OneShot.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ExampleList } from "../../components/Example";
1010
import { AnalysisPanel, AnalysisPanelTabs } from "../../components/AnalysisPanel";
1111
import { SettingsButton } from "../../components/SettingsButton/SettingsButton";
1212

13-
const OneShot = () => {
13+
export function Component(): JSX.Element {
1414
const [isConfigPanelOpen, setIsConfigPanelOpen] = useState(false);
1515
const [approach, setApproach] = useState<Approaches>(Approaches.RetrieveThenRead);
1616
const [promptTemplate, setPromptTemplate] = useState<string>("");
@@ -246,6 +246,6 @@ const OneShot = () => {
246246
</Panel>
247247
</div>
248248
);
249-
};
249+
}
250250

251-
export default OneShot;
251+
Component.displayName = "OneShot";

app/frontend/vite.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@ export default defineConfig({
77
build: {
88
outDir: "../backend/static",
99
emptyOutDir: true,
10-
sourcemap: true
10+
sourcemap: true,
11+
rollupOptions: {
12+
output: {
13+
manualChunks: id => {
14+
if (id.includes("@fluentui/react-icons")) {
15+
return "fluentui-icons";
16+
} else if (id.includes("@fluentui/react")) {
17+
return "fluentui-react";
18+
} else if (id.includes("node_modules")) {
19+
return "vendor";
20+
}
21+
}
22+
}
23+
}
1124
},
1225
server: {
1326
proxy: {

0 commit comments

Comments
 (0)