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: 이미지 최적화 #485

Merged
merged 15 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
3 changes: 1 addition & 2 deletions frontend/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
{
"runtime": "automatic"
}
],
"@babel/preset-typescript"
]
],
"plugins": [
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

const Dotenv = require('dotenv-webpack');

module.exports = {
mode: 'production',
mode: process.env.NODE_ENV,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

entry: ['./src/index.tsx'],
output: {
path: path.resolve(__dirname, '../dist/'),
publicPath: '/',
filename: '[name].[chunkhash:8].js',
Copy link
Collaborator

Choose a reason for hiding this comment

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

chunkhash:8이면 8자리로 나오는 건가요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 하면 해쉬값으로 식별을 하여 캐시 버스팅할 수 있겠네요

clean: true,
},
resolve: {
Expand Down Expand Up @@ -61,15 +57,4 @@ module.exports = {
historyApiFallback: true,
allowedHosts: 'all',
},

plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
filename: 'index.html',
}),
new ForkTsCheckerWebpackPlugin(),
new Dotenv({
path: path.resolve(__dirname, `../.dev.env`),
}),
],
};
36 changes: 23 additions & 13 deletions frontend/.webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
const productionConfig = require('./webpack.prod.js');
const developmentConfig = require('./webpack.dev.js');
const localConfig = require('./webpack.local.js');
const path = require('path');
const commonConfig = require('./webpack.common.js');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const Dotenv = require('dotenv-webpack');

const commonPlugins = [
new HtmlWebpackPlugin({
template: './public/index.html',
filename: 'index.html',
}),
new ForkTsCheckerWebpackPlugin(),
];

module.exports = (env, args) => {
const { TARGET_ENV } = env;

switch (TARGET_ENV) {
case 'msw':
return localConfig;
case 'dev':
return developmentConfig;
case 'prod':
return productionConfig;
default:
throw new Error('No matching configuration was found!');
}
return {
...commonConfig,
plugins: [
...commonPlugins,
new Dotenv({
path: path.resolve(__dirname, `../.${TARGET_ENV}.env`),
}),
],
};
};
77 changes: 0 additions & 77 deletions frontend/.webpack/webpack.local.js

This file was deleted.

16 changes: 8 additions & 8 deletions frontend/cypress/fixtures/restaurants.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"images": [
{
"id": 355,
"name": "UmF3RmlzaEVhdGVyX-uwlOydtO2CueyKpOybjO2UhF_roa_rjbDsm5Trk5zrqrDsoJA.jpeg",
"name": "UmF3RmlzaEVhdGVyX-uwlOydtO2CueyKpOybjO2UhF_roa_rjbDsm5Trk5zrqrDsoJA",
"author": "@RawFishEater",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -54,7 +54,7 @@
"images": [
{
"id": 63,
"name": "bW9uc3RlcmdvdXJtZXRf7Y6Y66mU7KKF.jpeg",
"name": "bW9uc3RlcmdvdXJtZXRf7Y6Y66mU7KKF",
"author": "@monstergourmet",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -84,7 +84,7 @@
"images": [
{
"id": 136,
"name": "bGl3b29f66q965Oc7IOs66Gv.jpeg",
"name": "bGl3b29f66q965Oc7IOs66Gv",
"author": "@Liwoo_foodie",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -114,7 +114,7 @@
"images": [
{
"id": 121,
"name": "bWFyaWFnZV_rjIDshLHsl7Dtg4TqsIjruYQ.jpeg",
"name": "bWFyaWFnZV_rjIDshLHsl7Dtg4TqsIjruYQ",
"author": "@mariage_in",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -144,7 +144,7 @@
"images": [
{
"id": 151,
"name": "bGl3b29f66-47YOA7Jqw64-Z.jpeg",
"name": "bGl3b29f66-47YOA7Jqw64-Z",
"author": "@Liwoo_foodie",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -174,7 +174,7 @@
"images": [
{
"id": 330,
"name": "UmF3RmlzaEVhdGVyX-2YleygnOyDge2ajF_qsIDrnb3rqrDsp4DsoJA.jpeg",
"name": "UmF3RmlzaEVhdGVyX-2YleygnOyDge2ajF_qsIDrnb3rqrDsp4DsoJA",
"author": "@RawFishEater",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -204,7 +204,7 @@
"images": [
{
"id": 183,
"name": "bGl3b29f6re4656c65Oc7JuM7Luk7Z6Q7ISc7Jq4642U7YyM67mM66as7Jio.jpeg",
"name": "bGl3b29f6re4656c65Oc7JuM7Luk7Z6Q7ISc7Jq4642U7YyM67mM66as7Jio",
"author": "@Liwoo_foodie",
"sns": "YOUTUBE"
}
Expand Down Expand Up @@ -234,7 +234,7 @@
"images": [
{
"id": 92,
"name": "bWFyaWFnZV_sgrDqs7zrsJTri6Q.jpeg",
"name": "bWFyaWFnZV_sgrDqs7zrsJTri6Q",
"author": "@mariage_in",
"sns": "YOUTUBE"
}
Expand Down
44 changes: 22 additions & 22 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"main": "index.tsx",
"license": "MIT",
"scripts": {
"start:msw": "webpack serve --port 3000 --env TARGET_ENV=msw",
"start:dev": "webpack serve --port 3000 --env TARGET_ENV=dev",
"start:prod": "webpack serve --port 3000 --env TARGET_ENV=prod",
"build:dev": "webpack --env TARGET_ENV=dev",
"build:prod": "webpack --env TARGET_ENV=prod",
"start:msw": "webpack serve --port 3000 --env TARGET_ENV=msw --mode development",
"start:dev": "webpack serve --port 3000 --env TARGET_ENV=dev --mode production",
"start:prod": "webpack serve --port 3000 --env TARGET_ENV=prod --mode production",
Comment on lines +7 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 msw에 전용 환경 구성은 못할까요??

"build:dev": "webpack --env TARGET_ENV=dev --mode production",
"build:prod": "webpack --env TARGET_ENV=prod --mode production",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:css": "stylelint './src/**/*.{tsx,ts,jsx,js}'",
"lint:css:fix": "stylelint './src/**/*.{tsx,ts,jsx,js}' --fix",
Expand All @@ -21,36 +21,36 @@
},
"dependencies": {
"@googlemaps/react-wrapper": "^1.1.35",
"@storybook/react": "^7.0.25",
"@storybook/react-webpack5": "^7.0.25",
"@tanstack/react-query": "^4.32.0",
"@tanstack/react-query-devtools": "^4.32.0",
"@testing-library/jest-dom": "^5.16.5",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@types/styled-components": "^5.1.26",
"axios": "^1.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.2",
"styled-components": "^6.0.2",
"zustand": "^4.3.9",
"typescript": "^5.1.6"
},
"devDependencies": {
"@types/styled-components": "^5.1.26",
"ts-loader": "^9.4.4",
"babel-plugin-root-import": "^6.6.0",
"copy-webpack-plugin": "^11.0.0",
"cypress": "^12.17.3",
"dotenv": "^16.3.1",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"html-webpack-plugin": "^5.5.3",
"msw": "^1.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.2",
"copy-webpack-plugin": "^11.0.0",
"@tanstack/react-query-devtools": "^4.32.0",
"@testing-library/jest-dom": "^5.16.5",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@storybook/react": "^7.0.25",
"@storybook/react-webpack5": "^7.0.25",
"storybook": "^7.0.25",
"styled-components": "^6.0.2",
"ts-loader": "^9.4.4",
"typescript": "^5.1.6",
"webpack": "^5.88.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.9.0",
"zustand": "^4.3.9"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@babel/preset-react": "^7.22.5",
Expand Down
Binary file removed frontend/src/assets/all.png
Binary file not shown.
18 changes: 16 additions & 2 deletions frontend/src/components/@common/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Modal } from '~/components/@common/Modal';
import useToastState from '~/hooks/store/useToastState';
import useMediaQuery from '~/hooks/useMediaQuery';
import { BORDER_RADIUS, FONT_SIZE } from '~/styles/common';
import getImgUrl from '~/utils/image';

interface StyledToastProps {
isSuccess?: boolean;
Expand All @@ -20,7 +21,12 @@ function Toast() {
<Modal open={open} close={close} isOpen={isOpen}>
{isOpen && (
<StyledToastWrapper isSuccess={isSuccess} isMobile={isMobile}>
{image && <StyledToastImg src={`https://www.celuveat.com/images-data/${image.url}`} alt={image.alt} />}
{image && (
<picture>
<StyledToastSource type="image/webp" srcSet={`${getImgUrl(image.url, 'webp')}`} />
<StyledToastImg src={`${getImgUrl(image.url, 'jpeg')}`} alt={image.alt} />
Comment on lines +26 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

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

함수화되었으면 string으로 안 묶어줘도 될 것 같아요!

Copy link
Collaborator

Choose a reason for hiding this comment

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

webp 미지원 브라우저에 대한 대응도 잘 해주셨네요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정했습니다!!

</picture>
)}
<StyledToastText>{text}</StyledToastText>
</StyledToastWrapper>
)}
Expand All @@ -30,13 +36,21 @@ function Toast() {

export default Toast;

const StyledToastImg = styled.img`
const styledToastImgVariable = css`
width: 44px;
height: 44px;

border-radius: ${BORDER_RADIUS.sm};
`;

const StyledToastImg = styled.img`
${styledToastImgVariable}
`;

const StyledToastSource = styled.source`
${styledToastImgVariable}
`;

Comment on lines -33 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

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

아마 같은 css를 두 군데에서 다 쓰려고 묶은 것 같네요! 저는 공용css 만 묶어주었던지라.. 이런 상황에서picture > * 를 쓸 것 같아요! 어떤가요?

Copy link
Collaborator

@shackstack shackstack Sep 20, 2023

Choose a reason for hiding this comment

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

source 태그에 대한 스타일드 컴포넌트는 왜 만드신건가요?

picture 태그 사용에 미숙해서 생긴 코드 같습니다! 숙지 후 수정했습니다!!

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 가 불필요해서 삭제했습니다!!

picture > * picture라는 태그에 자식 요소에 스타일을 공통적으로 묶을 수 있어서 좋을 것 같습니다!!

const StyledToastText = styled.span`
color: var(--gary-4);
`;
Expand Down
Loading
Loading