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

Bundle 사이즈 최적화 #716

Merged
merged 16 commits into from
Oct 4, 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
155 changes: 155 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
"dev": "webpack-dev-server --config webpack.dev.js --open",
"tsc": "tsc --noEmit",
"build": "webpack --mode production --config webpack.prod.js",
"build:report": "webpack-bundle-analyzer --port 8888 dist/bundle-stats.json",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"lint:style": "stylelint '**/style.ts' --fix"
},
"keywords": [],
"author": "",
"sideEffects": [
"./src/routes/router.tsx"
],
"license": "ISC",
"dependencies": {
"@emotion/react": "^11.11.4",
Expand Down Expand Up @@ -80,6 +84,7 @@
"undici": "^6.19.2",
"util": "^0.12.5",
"webpack": "^5.92.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Toast/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';

import * as S from './Toast.style';

Expand Down
73 changes: 53 additions & 20 deletions frontend/src/routes/router.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
import { ErrorBoundary } from '@sentry/react';
import { Suspense } from 'react';
import { lazy, Suspense } from 'react';
import { createBrowserRouter } from 'react-router-dom';

import { Layout, LoadingFallback } from '@/components';
import {
TemplatePage,
TemplateUploadPage,
SignupPage,
LoginPage,
LandingPage,
NotFoundPage,
TemplateExplorePage,
MyTemplatePage,
} from '@/pages';

import RouteGuard from './RouteGuard';
import { END_POINTS } from './endPoints';

const LandingPage = lazy(() => import('@/pages/LandingPage/LandingPage'));
const TemplatePage = lazy(() => import('@/pages/TemplatePage/TemplatePage'));
const TemplateUploadPage = lazy(() => import('@/pages/TemplateUploadPage/TemplateUploadPage'));
const SignupPage = lazy(() => import('@/pages/SignupPage/SignupPage'));
const LoginPage = lazy(() => import('@/pages/LoginPage/LoginPage'));
const NotFoundPage = lazy(() => import('@/pages/NotFoundPage/NotFoundPage'));
const TemplateExplorePage = lazy(() => import('@/pages/TemplateExplorePage/TemplateExplorePage'));
const MyTemplatePage = lazy(() => import('@/pages/MyTemplatesPage/MyTemplatePage'));
Comment on lines +10 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 lint 에러가 나지 않았나요?!
Fast refresh only works when a file only exports components. Move your component(s) to a separate file.eslint(react-refresh/only-export-components)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 부분에 ESLint 에러가 발생하고 있습니다.

이 에러는 DX 향상 목적의 에러인데요.
소스코드 변경 시, 브라우저에서 해당 부분만 빠르게 업데이트하여 개발생산성을 높힐 수 있다는 경고입니다.

이 ESLint 에러 같은 경우에는 컴포넌트의 Default export 또는 컴포넌트를 리턴하고 있지 않아서 발생한다고 하는데, lazy 로딩을 사용할 수 없게 됩니다.

따라서 ESLint에서 이 에러를 경고처리만 하여서 개발자가 파악할 수 있도록 하여 사용하는 케이스도 있다고 합니다.


const CustomSuspense = ({ children }: { children: JSX.Element }) => (
<Suspense fallback={<div>Loading...</div>}>{children}</Suspense>
);
Comment on lines +19 to +21
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분에서 혹시 LayoutShift가 생기진 않나요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Layout의 모든 요소가 한 번에 렌더링 되기 때문에 Layout Shift가 생기진 않지만, (캐시가 없을 때) 로딩 후 뒤늦게 렌더링 됩니다.

헤인이 Footer이 미리 렌더링 되지 않도록 하여 Layout Shift를 해결했던 것과 동일한 이유로 Layout Shift가 발생하지 않는다고 할 수 있을 것 같습니다.


const router = createBrowserRouter([
{
errorElement: <NotFoundPage />,
element: <Layout />,
errorElement: (
<CustomSuspense>
<NotFoundPage />
</CustomSuspense>
),
Comment on lines +26 to +29
Copy link
Contributor

Choose a reason for hiding this comment

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

CustomSuspense를 Layout 내부 같은 곳에서 한번에 걸어도 괜찮을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

제가 지금 생각했을 땐 방법이 떠오르지는 않네용
같이 이야기 해 볼 사항인 것 같습니다.

element: (
<CustomSuspense>
<Layout />
</CustomSuspense>
),
children: [
{
path: END_POINTS.HOME,
element: <LandingPage />,
element: (
<CustomSuspense>
<LandingPage />
</CustomSuspense>
),
},
{
path: END_POINTS.MY_TEMPLATES,
Expand All @@ -40,39 +55,57 @@ const router = createBrowserRouter([
},
{
path: END_POINTS.TEMPLATES_EXPLORE,
element: <TemplateExplorePage />,
element: (
<CustomSuspense>
<TemplateExplorePage />
</CustomSuspense>
),
},
{
path: END_POINTS.TEMPLATE,
element: <TemplatePage />,
element: (
<CustomSuspense>
<TemplatePage />
</CustomSuspense>
),
},
{
path: END_POINTS.TEMPLATES_UPLOAD,
element: (
<RouteGuard isLoginRequired redirectTo={END_POINTS.LOGIN}>
<TemplateUploadPage />
<CustomSuspense>
<TemplateUploadPage />
</CustomSuspense>
</RouteGuard>
),
},
{
path: END_POINTS.SIGNUP,
element: (
<RouteGuard isLoginRequired={false} redirectTo={END_POINTS.HOME}>
<SignupPage />
<CustomSuspense>
<SignupPage />
</CustomSuspense>
</RouteGuard>
),
},
{
path: END_POINTS.LOGIN,
element: (
<RouteGuard isLoginRequired={false} redirectTo={END_POINTS.HOME}>
<LoginPage />
<CustomSuspense>
<LoginPage />
</CustomSuspense>
</RouteGuard>
),
},
{
path: '*',
element: <NotFoundPage />,
element: (
<CustomSuspense>
<NotFoundPage />
</CustomSuspense>
),
},
],
},
Expand Down
1 change: 0 additions & 1 deletion frontend/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ module.exports = {
},
extensions: ['.tsx', '.ts', '.js'],
},
devtool: 'source-map',
};
Loading