From 7818c6f29068db2c44fa48dd76262ed5f7b67bc6 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Fri, 6 Mar 2026 12:37:45 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Build=20optimizations=20(chunkin?= =?UTF-8?q?g=20and=20lazy-loading)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ComicDetail/TabControls.tsx | 10 +++--- .../components/ComicDetail/tabConfig.tsx | 15 ++++----- src/client/index.tsx | 31 ++++++++++--------- vite.config.js | 28 +++++++++++++++++ 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/client/components/ComicDetail/TabControls.tsx b/src/client/components/ComicDetail/TabControls.tsx index ca1c1f9..5da5614 100644 --- a/src/client/components/ComicDetail/TabControls.tsx +++ b/src/client/components/ComicDetail/TabControls.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement, useState } from "react"; +import React, { ReactElement, Suspense, useState } from "react"; import { isNil } from "lodash"; export const TabControls = (props): ReactElement => { @@ -47,9 +47,11 @@ export const TabControls = (props): ReactElement => { - {filteredTabs.map(({ id, content }) => { - return currentActive === id ? content : null; - })} + + {filteredTabs.map(({ id, content }) => { + return currentActive === id ? content : null; + })} + ); }; diff --git a/src/client/components/ComicDetail/tabConfig.tsx b/src/client/components/ComicDetail/tabConfig.tsx index 3837863..8c006bc 100644 --- a/src/client/components/ComicDetail/tabConfig.tsx +++ b/src/client/components/ComicDetail/tabConfig.tsx @@ -1,11 +1,12 @@ -import React from "react"; +import React, { lazy } from "react"; import { isNil, isEmpty } from "lodash"; -import { VolumeInformation } from "./Tabs/VolumeInformation"; -import { ComicInfoXML } from "./Tabs/ComicInfoXML"; -import { ArchiveOperations } from "./Tabs/ArchiveOperations"; -import AcquisitionPanel from "./AcquisitionPanel"; -import TorrentSearchPanel from "./TorrentSearchPanel"; -import DownloadsPanel from "./DownloadsPanel"; + +const VolumeInformation = lazy(() => import("./Tabs/VolumeInformation").then(m => ({ default: m.VolumeInformation }))); +const ComicInfoXML = lazy(() => import("./Tabs/ComicInfoXML").then(m => ({ default: m.ComicInfoXML }))); +const ArchiveOperations = lazy(() => import("./Tabs/ArchiveOperations").then(m => ({ default: m.ArchiveOperations }))); +const AcquisitionPanel = lazy(() => import("./AcquisitionPanel")); +const TorrentSearchPanel = lazy(() => import("./TorrentSearchPanel")); +const DownloadsPanel = lazy(() => import("./DownloadsPanel")); interface TabConfig { id: number; diff --git a/src/client/index.tsx b/src/client/index.tsx index d15ee2c..9cbf6a1 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -1,22 +1,21 @@ -import React from "react"; -import { render } from "react-dom"; +import { lazy, Suspense } from "react"; import { createRoot } from "react-dom/client"; +const root = createRoot(document.getElementById("root")!); import App from "./components/App"; import { createBrowserRouter, RouterProvider } from "react-router-dom"; -import Settings from "./components/Settings/Settings"; import { ErrorPage } from "./components/shared/ErrorPage"; -const rootEl = document.getElementById("root"); -const root = createRoot(rootEl); -import i18n from "./shared/utils/i18n.util"; +import "./shared/utils/i18n.util"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import Import from "./components/Import/Import"; -import Dashboard from "./components/Dashboard/Dashboard"; -import Search from "./components/Search/Search"; -import TabulatedContentContainer from "./components/Library/TabulatedContentContainer"; -import { ComicDetailContainer } from "./components/ComicDetail/ComicDetailContainer"; -import Volumes from "./components/Volumes/Volumes"; -import VolumeDetails from "./components/VolumeDetail/VolumeDetail"; -import WantedComics from "./components/WantedComics/WantedComics"; + +const Settings = lazy(() => import("./components/Settings/Settings")); +const Import = lazy(() => import("./components/Import/Import")); +const Dashboard = lazy(() => import("./components/Dashboard/Dashboard")); +const Search = lazy(() => import("./components/Search/Search")); +const TabulatedContentContainer = lazy(() => import("./components/Library/TabulatedContentContainer")); +const ComicDetailContainer = lazy(() => import("./components/ComicDetail/ComicDetailContainer").then(m => ({ default: m.ComicDetailContainer }))); +const Volumes = lazy(() => import("./components/Volumes/Volumes")); +const VolumeDetails = lazy(() => import("./components/VolumeDetail/VolumeDetail")); +const WantedComics = lazy(() => import("./components/WantedComics/WantedComics")); const queryClient = new QueryClient({ defaultOptions: { @@ -55,6 +54,8 @@ const router = createBrowserRouter([ root.render( - + + + , ); diff --git a/vite.config.js b/vite.config.js index 538c111..8be5071 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,6 +7,34 @@ export default defineConfig({ base: "", build: { target: "esnext", + rollupOptions: { + output: { + manualChunks: { + "react-vendor": ["react", "react-dom", "react-router", "react-router-dom"], + "query-vendor": ["@tanstack/react-query", "@tanstack/react-table"], + "ui-vendor": [ + "styled-components", + "react-toastify", + "react-select", + "react-modal", + "react-sliding-pane", + "embla-carousel-react", + "react-day-picker", + "react-loader-spinner", + ], + "utils-vendor": [ + "lodash", + "date-fns", + "dayjs", + "axios", + "rxjs", + "socket.io-client", + "i18next", + "react-i18next", + ], + }, + }, + }, }, esbuild: { supported: {