/** * Public 폴더 에셋 경로 유틸리티 * * Vite의 base 설정을 적용하여 public 폴더의 에셋 경로를 반환합니다. * 서브 경로 배포 시 (예: /kcgv/) 자동으로 경로를 조정합니다. * * @example * // 개발 환경 (base: '/') * assetPath('/images/icon.svg') // → '/images/icon.svg' * * // 프로덕션 환경 (base: '/kcgv/') * assetPath('/images/icon.svg') // → '/kcgv/images/icon.svg' */ /** * public 폴더 에셋의 전체 경로를 반환 * @param {string} path - '/'로 시작하는 에셋 경로 (예: '/images/icon.svg') * @returns {string} base URL이 적용된 전체 경로 */ export function assetPath(path) { // import.meta.env.BASE_URL은 항상 '/'로 끝남 (예: '/', '/kcgv/') const base = import.meta.env.BASE_URL; // path가 '/'로 시작하면 제거하여 중복 방지 const cleanPath = path.startsWith('/') ? path.slice(1) : path; return base + cleanPath; } /** * 이미지 경로를 위한 단축 함수 * @param {string} filename - 이미지 파일명 (예: 'icon.svg', 'photo.png') * @returns {string} base URL이 적용된 전체 이미지 경로 */ export function imagePath(filename) { return assetPath(`/images/${filename}`); } export default assetPath;