Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/lazyloading #20

Merged
merged 10 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css">
<title>Blank</title>
</head>
<body>
Expand Down
20 changes: 11 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { Suspense } from "react";
import Layout from "./components/Layout";
import routerInfo from "./shared/routing/routerInfo.tsx";

const RouterPath = routerInfo.map((info) => {
return {
path: info.path,
element: info.element,
};
});
import routerInfo from "./shared/routing/routerInfo";

const router = createBrowserRouter([
{
path: "/",
element: <Layout />,
children: RouterPath,
children: routerInfo.map(({ path, element: Element }) => ({
path,
element: (
<Suspense fallback={<div>Loading...</div>}>
<Element />
</Suspense>
),
})),
},
]);

function App() {
return <RouterProvider router={router} />;
}

export default App;
2 changes: 1 addition & 1 deletion src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useRef, useState } from "react";
import { Link, matchPath, useLocation } from "react-router-dom";
import routerInfo from "../../shared/routing/routerInfo.tsx";
import routerInfo from "../../shared/routing/routerInfo";
import Logo from "../../assets/logo.svg?react";
import Menu from "../../assets/menu_buton.json";
import {
Expand Down
3 changes: 3 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import url("https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

css 초기화 로직인데 그냥 가져왔습니다.
중복 여부 및 수정 방안 제시 부탁드립니다. @dandamdandam

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/jjh4450/KNU-festival24/blob/874601fc3ba4f9dd53864e3a297d9ec95f00c438/index.html#L7

이전에 작성해둔 건데, index.css에서 관리하는게 더 좋아보입니다. index.html에 위 코드 삭제해주세요!

@import url("https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/variable/pretendardvariable-dynamic-subset.min.css");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0");
1 change: 1 addition & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./index.css";

import App from "./App";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,73 @@
import { lazy } from "react";
import { routerInfoType } from "../types/routing.ts";
import Main from "../../pages/Main";
import Artist from "../../pages/Artist";
import Booth from "../../pages/Booth";
import BoothNFoodList from "../../pages/BoothNFoodList";
import Foodtruck from "../../pages/Foodtruck";
import Makers from "../../pages/Makers";
import Map from "../../pages/Map";
import Notice from "../../pages/Notice";
import QnA from "../../pages/QnA";
import Timetable from "../../pages/Timetable";

export const routerInfo: routerInfoType[] = [
{
path: "/",
element: <Main />,
element: lazy(() => import("../../pages/Main")),
english: "Main",
korean: "메인",
expose: true,
},
{
path: "artist/:id",
element: <Artist />,
element: lazy(() => import("../../pages/Artist")),
english: "Artist",
korean: "아티스트",
expose: false,
},
{
path: "booth/:id",
element: <Booth />,
element: lazy(() => import("../../pages/Booth")),
english: "Booth",
korean: "부스",
expose: false,
},
{
path: "booth_foodtruck_list",
element: <BoothNFoodList />,
element: lazy(() => import("../../pages/BoothNFoodList")),
english: "Booth & Foodtruck List",
korean: "부스 & 푸드트럭 리스트",
expose: true,
},
{
path: "foodtruck/:id",
element: <Foodtruck />,
element: lazy(() => import("../../pages/Foodtruck")),
english: "Foodtruck",
korean: "푸드트럭",
expose: false,
},
{
path: "makers",
element: <Makers />,
element: lazy(() => import("../../pages/Makers")),
english: "Makers",
korean: "메이커스",
expose: false,
},
{
path: "map",
element: <Map />,
element: lazy(() => import("../../pages/Map")),
english: "Map",
korean: "지도",
expose: true,
},
{
path: "notice",
element: <Notice />,
element: lazy(() => import("../../pages/Notice")),
english: "Notice",
korean: "공지사항",
expose: true,
},
{
path: "QnA",
element: <QnA />,
element: lazy(() => import("../../pages/QnA")),
english: "QnA",
korean: "QnA",
expose: true,
},
{
path: "timetable",
element: <Timetable />,
element: lazy(() => import("../../pages/Timetable")),
english: "Timetable",
korean: "타임테이블",
expose: true,
Expand Down
7 changes: 1 addition & 6 deletions src/shared/styles/vars.css.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { createGlobalTheme, fontFace } from "@vanilla-extract/css";

const pretendardRegular = fontFace({
src: "url('https://fastly.jsdelivr.net/gh/Project-Noonnu/[email protected]/Pretendard-Regular.woff') format('woff')",
fontWeight: 400,
fontStyle: "normal",
});
const pyeongChangBold = fontFace({
src: "url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/PyeongChangPeace-Bold.woff2') format('woff2');",
fontWeight: 700,
Expand All @@ -27,7 +22,7 @@ export const vars = createGlobalTheme("#root", {
white: "#FFFFFF",
},
font: {
pretendardRegular,
pretendardRegular: "pretendard, sans-serif", // for debug: ,Courier New", // <-독특함
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

폰트 import 최적화를 수행했습니다.

  • 기존 폰트가 1.1메가로 너무 무거워 이를 서브셋 폰트로 적용했습니다.
    • 카톡방에 충분히 공유된 사항이어서 별도 이슈는 작성하지 않았습니다.
    • 본 브런치의 목적과 크게 다르지 않아 한 번에 포함했습니다.
  • src/index.css에 의존합니다

pyeongChangBold,
pyeongChangLight,
},
Expand Down
4 changes: 3 additions & 1 deletion src/shared/types/routing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 라우팅 정보 객체 타입
import React, { ComponentType } from "react";

export interface routerInfoType {
path: string;
element: React.ReactElement;
element: React.LazyExoticComponent<ComponentType<unknown>>;
english: string;
korean: string;
expose: boolean;
Expand Down
18 changes: 18 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ export default defineConfig({
}),
}),
],
build: {
rollupOptions: {
output: {
manualChunks: (id: string) => {
if (id.includes("node_modules")) {
const module: string = id.split("node_modules/").pop()!.split("/")[0];
if (module.includes("react")) {
return "react-vendor";
}
Comment on lines +36 to +38
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

번들링 최적화를 수행했습니다.
과도한 번들링은 오히려 오버헤드를 유발할 수 있을 거 같아, react 관련 라이브러리는 한데 모았습니다.

구현이 어렵지도 않았고, 용량이 그리 크지도 않아 따로 비교는 하지 않았습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나머지 모듈들은 따로 분리되어 필요할 때 import 됩니다.

// if (module.includes("poo")) {
// return "poo-vendor";
// }
return `vendor-${module}`;
}
},
},
},
},
});