예제
Nuxt Kit 유틸리티 사용 예제.
Nuxt Vite 설정 접근하기
Nuxt가 사용하는 런타임 Vite 또는 webpack 설정에 접근이 필요한 통합을 구축하는 경우, Kit 유틸리티를 사용하여 이를 추출할 수 있습니다.
이미 이를 수행하고 있는 프로젝트의 몇 가지 예:
프로젝트에서 Vite 설정에 접근하는 방법의 간단한 예는 다음과 같습니다. 유사한 접근 방식을 사용하여 webpack 설정을 얻을 수 있습니다.
import { loadNuxt, buildNuxt } from '@nuxt/kit'
// https://github.com/nuxt/nuxt/issues/14534
async function getViteConfig() {
const nuxt = await loadNuxt({ cwd: process.cwd(), dev: false, overrides: { ssr: false } })
return new Promise((resolve, reject) => {
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
if (isClient) {
resolve(config)
throw new Error('_stop_')
}
})
buildNuxt(nuxt).catch((err) => {
if (!err.toString().includes('_stop_')) {
reject(err)
}
})
}).finally(() => nuxt.close())
}
const viteConfig = await getViteConfig()
console.log(viteConfig)
※이 페이지는 Nuxt.js 공식 문서의 비공식 번역 페이지입니다.
공식 문서의 해당 페이지는 여기 있습니다:
https://nuxt.com/docs/3.x/api/kit/examples