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

[개인 미션 - 성능 오답노트] 윤생(이윤성) 미션 제출합니다. #79

Merged
merged 23 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8d3e1b0
build: minimizer 설정
2yunseong Sep 1, 2023
ebe2704
build: 명시적으로 sideEffects를 포함하지 않는 설정 - 명시적으로 sideEffects 가 false임을 표현
2yunseong Sep 1, 2023
ea5563b
chore: webpack bundle analyzer 설치
2yunseong Sep 1, 2023
1c16e01
build: contenthash 부착
2yunseong Sep 1, 2023
fb3efc9
chore: side effect 수정
2yunseong Sep 1, 2023
9a9c3ac
chore: node버전에 맞게 패키지 버전 수정
2yunseong Sep 1, 2023
a4dc9f5
chore: compression-webpack-plugin 설치
2yunseong Sep 1, 2023
076b20b
build: gzip 압축 코드 설치
2yunseong Sep 1, 2023
ddc9d73
refactor: 코드 스플리팅 적용
2yunseong Sep 1, 2023
603f913
refactor: 이미지 리사이징 및 확장자 변경
2yunseong Sep 1, 2023
3a2849d
build: minicssExtractPlugin 설치
2yunseong Sep 1, 2023
aeef1bd
refactor: sessionStorage를 활용한 api값 캐싱
2yunseong Sep 2, 2023
f1dd4e4
build: 빌드 시 주석을 제거해주는 설정 추가
2yunseong Sep 2, 2023
e167d6b
refactor: 불필요한 렌더링이 되는 요소에 메모이제이션 추가
2yunseong Sep 2, 2023
15e8945
refactor: Layout Shift 개선
2yunseong Sep 4, 2023
ee1c73b
fix: basename 제거
2yunseong Sep 4, 2023
bbdfa3d
fix: CLS 개선
2yunseong Sep 4, 2023
815d9f7
chore: css minimizer plugin 설치 및 적용
2yunseong Sep 4, 2023
10595e4
refactor: git -> mp4로 변경
2yunseong Sep 5, 2023
b4d7dbe
refactor: react icons 필요한 모듈만 import
2yunseong Sep 5, 2023
c70c10c
chore: 주석 제거
2yunseong Sep 6, 2023
c4a763a
build: optimize 옵션 명시로 코드 축약
2yunseong Sep 6, 2023
b0e656f
chore: 필요없는 패키지 명시 제거
2yunseong Sep 10, 2023
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
14,563 changes: 9,788 additions & 4,775 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"dependencies": {
"@giphy/js-fetch-api": "^4.1.1",
"@giphy/js-types": "^4.2.1",
"@react-icons/all-files": "^4.1.0",
shackstack marked this conversation as resolved.
Show resolved Hide resolved
"classnames": "^2.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.4.0",
"react-router-dom": "^6.3.0"
},
"devDependencies": {
Expand All @@ -33,13 +33,14 @@
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@webpack-cli/generators": "^2.2.0",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^6.2.0",
"css-minimizer-webpack-plugin": "^5.0.1",
"dotenv-webpack": "^7.0.3",
"eslint": "^7.32.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-hooks": "^0.4.3",
Expand All @@ -50,11 +51,13 @@
"file-loader": "^6.2.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.3.2",
"mini-css-extract-plugin": "^2.7.6",
"prettier": "^2.3.2",
"style-loader": "^3.2.1",
"ts-loader": "^9.3.1",
"typescript": "^4.8.2",
"webpack": "^5.50.0",
"webpack": "^5.88.2",
"webpack-bundle-analyzer": "^4.9.1",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
},
Expand Down
19 changes: 11 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Suspense } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';

import Home from './pages/Home/Home';
import Search from './pages/Search/Search';
const Home = React.lazy(() => import('./pages/Home/Home'));
const Search = React.lazy(() => import('./pages/Search/Search'));

import NavBar from './components/NavBar/NavBar';
import Footer from './components/Footer/Footer';
Expand All @@ -10,13 +11,15 @@ import './App.css';

const App = () => {
return (
<Router basename={'/perf-basecamp'}>
<Router>
<NavBar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/search" element={<Search />} />
</Routes>
<Footer />
<Suspense>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/search" element={<Search />} />
</Routes>
<Footer />
</Suspense>
</Router>
);
};
Expand Down
Binary file added src/assets/images/find.mp4
Binary file not shown.
Binary file added src/assets/images/free.mp4
Binary file not shown.
Binary file removed src/assets/images/hero.png
Binary file not shown.
Binary file added src/assets/images/hero.webp
Binary file not shown.
Binary file added src/assets/images/trending.mp4
Binary file not shown.
14 changes: 7 additions & 7 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { useRef } from 'react';
import { Link } from 'react-router-dom';
import classNames from 'classnames/bind';

import heroImage from '../../assets/images/hero.png';
import trendingGif from '../../assets/images/trending.gif';
import findGif from '../../assets/images/find.gif';
import freeGif from '../../assets/images/free.gif';
import heroImage from '../../assets/images/hero.webp';
import trendingMp4 from '../../assets/images/trending.mp4';
import findMp4 from '../../assets/images/find.mp4';
import freeMp4 from '../../assets/images/free.mp4';

Choose a reason for hiding this comment

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

webp 미지원 브라우저에 대한 대응도 있으면 좋을 것 같아요.
스크린샷 2023-09-10 오전 9 52 17

Choose a reason for hiding this comment

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

그리고 공원 강의에서 잠깐 소개되었던 건데, 애플에서 만든 heic도 용량대비 품질이 webp보다 좋더라구요.

스크린샷 2023-09-10 오전 9 52 58

하지만 지원하는 곳이 한군데 뿐이네요..

Copy link
Author

Choose a reason for hiding this comment

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

역시 애플꺼라고 사파리만..


import FeatureItem from './components/FeatureItem/FeatureItem';
import CustomCursor from './components/CustomCursor/CustomCursor';
Expand Down Expand Up @@ -33,9 +33,9 @@ const Home = () => {
<div className={styles.featureSectionWrapper}>
<h2 className={styles.featureTitle}>Features</h2>
<div className={styles.featureItemContainer}>
<FeatureItem title="See trending gif" imageSrc={trendingGif} />
<FeatureItem title="Find gif for free" imageSrc={findGif} />
<FeatureItem title="Free for everyone" imageSrc={freeGif} />
<FeatureItem title="See trending gif" videoSrc={trendingMp4} />
<FeatureItem title="Find gif for free" videoSrc={findMp4} />
<FeatureItem title="Free for everyone" videoSrc={freeMp4} />
</div>
<Link to="/search">
<button className={styles.linkButton}>start search</button>
Expand Down
12 changes: 5 additions & 7 deletions src/pages/Home/components/CustomCursor/CustomCursor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEffect, useRef } from 'react';
import { memo, useEffect, useRef } from 'react';
import useMousePosition from '../../hooks/useMousePosition';

import styles from './CustomCursor.module.css';
import CustomCursorChar from './CustomCursorChar';

type CustomCursorProps = {
text: string;
Expand All @@ -14,20 +15,17 @@ const CustomCursor = ({ text = '' }: CustomCursorProps) => {

useEffect(() => {
if (cursorRef.current) {
cursorRef.current.style.top = `${mousePosition.pageY}px`;
cursorRef.current.style.left = `${mousePosition.pageX}px`;
cursorRef.current.style.transform = `translate(${mousePosition.pageX}px, ${mousePosition.pageY}px)`;

Choose a reason for hiding this comment

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

👍

}
}, [mousePosition]);

return (
<div ref={cursorRef} className={styles.cursor}>
{cursorTextChars.map((char, index) => (
<span key={index} className={styles.character}>
{char}
</span>
<CustomCursorChar key={index} char={char} />

Choose a reason for hiding this comment

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

👍

))}
</div>
);
};

export default CustomCursor;
export default memo(CustomCursor);
11 changes: 11 additions & 0 deletions src/pages/Home/components/CustomCursor/CustomCursorChar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styles from './CustomCursor.module.css';
import { memo } from 'react';
interface CustomeCursorCharProps {
char: string;
}

const CustomCursorChar = ({ char }: CustomeCursorCharProps) => {
return <span className={styles.character}>{char}</span>;
};

export default memo(CustomCursorChar);
8 changes: 5 additions & 3 deletions src/pages/Home/components/FeatureItem/FeatureItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import styles from './FeatureItem.module.css';

type FeatureItemProps = {
title: string;
imageSrc: string;
videoSrc: string;
};

const FeatureItem = ({ title, imageSrc }: FeatureItemProps) => {
const FeatureItem = ({ title, videoSrc }: FeatureItemProps) => {
return (
<div className={styles.featureItem}>
<img className={styles.featureImage} src={imageSrc} />
<video className={styles.featureImage} autoPlay loop playsInline muted>
<source src={videoSrc} type="video/mp4" />
</video>
<div className={styles.featureTitleBg}></div>
<h4 className={styles.featureTitle}>{title}</h4>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/components/GifItem/GifItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

.gifItem:hover {
top: -0.75rem;
transform: translateY(-0.75rem);
}

.gifImage {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Search/components/GifItem/GifItem.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { memo } from 'react';
import { GifImageModel } from '../../../../models/image/gifImage';

import styles from './GifItem.module.css';
Expand All @@ -16,4 +17,4 @@ const GifItem = ({ imageUrl = '', title = '' }: GifItemProps) => {
);
};

export default GifItem;
export default memo(GifItem);
2 changes: 1 addition & 1 deletion src/pages/Search/components/HelpPanel/HelpPanel.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

.selectedItemContainer.showSheet {
right: 0;
transform: translateX(-320px);
opacity: 1;
}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/Search/components/HelpPanel/HelpPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { AiOutlineInfo, AiOutlineClose } from 'react-icons/ai';
import { AiOutlineInfo } from '@react-icons/all-files/ai/AiOutlineInfo';
import { AiOutlineClose } from '@react-icons/all-files/ai/AiOutlineClose';
import classNames from 'classnames/bind';

import { artists } from '../../../../constants/artistData';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AiOutlineSearch } from 'react-icons/ai';
import { AiOutlineSearch } from '@react-icons/all-files/ai/AiOutlineSearch';

import styles from './SearchBar.module.css';

Expand Down
10 changes: 9 additions & 1 deletion src/pages/Search/hooks/useGifSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ const useGifSearch = () => {
useEffect(() => {
const fetch = async () => {
if (status === SEARCH_STATUS.BEFORE_SEARCH) {
const gifs: GifImageModel[] = await gifAPIService.getTrending();
if (!sessionStorage.getItem('trending')) {
const newTrendingGifs = await gifAPIService.getTrending();
sessionStorage.setItem('trending', JSON.stringify(newTrendingGifs));
}

const cachedTrendingGifs = sessionStorage.getItem('trending');
if (!cachedTrendingGifs) return;

const gifs: GifImageModel[] = JSON.parse(cachedTrendingGifs);
Comment on lines +60 to +68

Choose a reason for hiding this comment

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

👍


setGifList(gifs);
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/images.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ declare module '*.png';
declare module '*.jpg';
declare module '*.gif';
declare module '*.svg';
declare module '*.webp';
declare module '*.mp4';
16 changes: 11 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
entry: './src/index.tsx',
resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx'] },
output: {
filename: 'bundle.js',
filename: '[contenthash].js',
path: path.join(__dirname, '/dist'),
clean: true
},
Expand All @@ -24,7 +27,9 @@ module.exports = {
new CopyWebpackPlugin({
patterns: [{ from: './public', to: './public' }]
}),
new Dotenv()
new Dotenv(),
new BundleAnalyzerPlugin(),
new MiniCssExtractPlugin()
],
module: {
rules: [
Expand All @@ -37,10 +42,10 @@ module.exports = {
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
use: [MiniCssExtractPlugin.loader, 'css-loader']

Choose a reason for hiding this comment

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

이렇게 바꿔주신 이유가 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

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

css를 압축하기 위해 별도의 loader를 사용하려고 하였습니다!

},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif|webp|mp4)$/i,
loader: 'file-loader',
options: {
name: 'static/[name].[ext]'
Expand All @@ -49,6 +54,7 @@ module.exports = {
]
},
optimization: {
minimize: false
minimize: true,
minimizer: [new CssMinimizerPlugin(), '...']
}
};