fix: orval mutator의 import.meta cjs 경고 제거
api.ts 가 orval mutator 로 esbuild 에 의해 cjs 번들될 때 `import.meta` 가 빈 객체로 처리되어 SDK 재생성 로그에 경고가 계속 떴음. vite `define` 으로 빌드 타임에 글로벌 상수로 치환하는 방식으로 우회. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>main
parent
5f7e0051cd
commit
e0610df826
|
|
@ -8,7 +8,10 @@
|
|||
*/
|
||||
import ky, { type KyInstance } from 'ky'
|
||||
|
||||
const API_BASE_URL = (import.meta.env.VITE_API_BASE_URL ?? '').replace(/\/$/, '')
|
||||
// import.meta 를 직접 쓰지 않는 이유: orval 이 mutator 를 cjs 로 esbuild 번들하는 과정에서
|
||||
// `import.meta is not available in cjs` 경고가 떠 SDK 재생성 로그가 시끄럽다.
|
||||
// 대신 vite.config.ts 의 `define` 으로 빌드 타임 치환되는 글로벌을 사용한다.
|
||||
const API_BASE_URL = (__VITE_API_BASE_URL__ ?? '').replace(/\/$/, '')
|
||||
|
||||
export const kyInstance: KyInstance = ky.create({
|
||||
timeout: 10_000,
|
||||
|
|
@ -18,7 +21,7 @@ export const kyInstance: KyInstance = ky.create({
|
|||
hooks: {
|
||||
beforeRequest: [
|
||||
(request) => {
|
||||
const apiKey = import.meta.env.VITE_API_KEY;
|
||||
const apiKey = __VITE_API_KEY__;
|
||||
if (apiKey) request.headers.set('x-api-key', apiKey);
|
||||
},
|
||||
// TODO: 인증 토큰 주입
|
||||
|
|
|
|||
|
|
@ -8,3 +8,7 @@ interface ImportMetaEnv {
|
|||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
||||
// vite.config.ts `define` 로 빌드 시 치환되는 글로벌 — api 모듈에서 import.meta 회피용
|
||||
declare const __VITE_API_BASE_URL__: string;
|
||||
declare const __VITE_API_KEY__: string;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ export default defineConfig(({ mode }) => {
|
|||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
// src/shared/api/api.ts 가 orval 의 mutator 로 cjs 번들될 때 `import.meta` 가 비어
|
||||
// 경고가 뜨던 문제를 우회. Vite 가 빌드 타임에 아래 글로벌을 실값으로 치환한다.
|
||||
define: {
|
||||
__VITE_API_BASE_URL__: JSON.stringify(env.VITE_API_BASE_URL ?? ''),
|
||||
__VITE_API_KEY__: JSON.stringify(env.VITE_API_KEY ?? ''),
|
||||
},
|
||||
server: {
|
||||
port: 3000,
|
||||
host: '0.0.0.0',
|
||||
|
|
|
|||
Loading…
Reference in New Issue