ship-gis/src/utils/assetPath.js
HeungTak Lee a5131306c4 feat: 앱 구조 개선 및 공통 컴포넌트
- publish 영역 lazy loading 적용 (빌드 시 tree-shaking)
- Toast 공통 컴포넌트 추가
- assetPath 유틸 추가 (BASE_URL 기반 경로 해석)
- csvDownload 유틸 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 06:35:50 +09:00

40 lines
1.2 KiB
JavaScript

/**
* 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;