Skip to content

Commit

Permalink
fix: prd 인 경우만 이미지 최적화 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ojj1123 committed Mar 27, 2024
1 parent f5206cb commit ea7f2df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions config/base.next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const IS_PROD = process.env.NODE_ENV === "production";
const isProd = process.env.NODE_ENV === "production";
const cloudName = process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME || "";

// The folders containing files importing twin.macro
const path = require("path");
Expand Down Expand Up @@ -62,6 +63,7 @@ module.exports = () => ({
return config;
},
images: {
unoptimized: !isProd || !cloudName,
// Link: https://fe-developers.kakaoent.com/2022/220714-next-image/
deviceSizes: [440],
imageSizes: [100, 200],
Expand All @@ -74,6 +76,6 @@ module.exports = () => ({
// https://webpack.js.org/configuration/devtool/ and
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map
// for more information.
hideSourceMaps: IS_PROD,
hideSourceMaps: isProd,
},
});
10 changes: 6 additions & 4 deletions config/cloudinary-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { ImageLoaderProps } from "next/image";

const cloudName = process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME;
const cloudName = process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME || "";

export function cloudinaryLoader({ src, width, quality }: ImageLoaderProps) {
const rawTransformations = ["f_auto", "c_limit", `w_${width}`, `q_${quality || "auto"}`];
Expand All @@ -18,7 +18,9 @@ export function cloudinaryLoader({ src, width, quality }: ImageLoaderProps) {
isAbsolute = true;
}

return isAbsolute
? `https://res.cloudinary.com/${cloudName}/image/fetch/${rawTransformations.join(",")}/${href}`
: src;
const cldUrl = `https://res.cloudinary.com/${cloudName}/image/fetch/${rawTransformations.join(
",",
)}/${href}`;

return isAbsolute ? cldUrl : src;
}

0 comments on commit ea7f2df

Please sign in to comment.