Skip to content

Commit 096f82e

Browse files
committed
fix: 이미지 최적화 시점을 빌드 이전 config 시점에 수행되도록 변경
1 parent b83104e commit 096f82e

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

.vitepress/plugins/image-optimizer.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,32 @@ export function createImageOptimizerPlugin(options: ImageOptimizerOptions = {}):
104104
formats = ["webp", "jpeg"],
105105
} = options;
106106

107+
let isOptimized = false;
108+
107109
return {
108110
name: "vitepress-image-optimizer",
109111

110-
async buildStart() {
111-
console.log("🖼️ 이미지 최적화 시작...");
112+
async config() {
113+
if (!isOptimized) {
114+
console.log("🖼️ 이미지 최적화 시작...");
112115

113-
try {
114-
const imagePaths = await glob(sourcePattern, {
115-
cwd: process.cwd(),
116-
absolute: true,
117-
});
116+
try {
117+
const imagePaths = await glob(sourcePattern, {
118+
cwd: process.cwd(),
119+
absolute: true,
120+
});
118121

119-
console.log(`📁 발견된 이미지: ${imagePaths.length}개`);
122+
console.log(`📁 발견된 이미지: ${imagePaths.length}개`);
120123

121-
for (const imagePath of imagePaths) {
122-
await convertImage(imagePath, formats, options);
123-
}
124+
for (const imagePath of imagePaths) {
125+
await convertImage(imagePath, formats, options);
126+
}
124127

125-
console.log("✅ 이미지 최적화 완료!");
126-
} catch (error) {
127-
console.error("❌ 이미지 최적화 실패:", error);
128+
console.log("✅ 이미지 최적화 완료!");
129+
isOptimized = true;
130+
} catch (error) {
131+
console.error("❌ 이미지 최적화 실패:", error);
132+
}
128133
}
129134
},
130135
};

0 commit comments

Comments
 (0)