Nuxt가 사용하는 런타임 Vite 또는 webpack 설정에 접근해야 하는 통합 기능을 만들고 있다면, Kit 유틸리티를 사용해 이를 추출할 수 있습니다.
이미 이를 사용하고 있는 프로젝트의 예시는 다음과 같습니다:
다음은 프로젝트에서 Vite 설정에 접근하는 간단한 예시입니다. 비슷한 접근 방식으로 webpack 설정도 가져올 수 있습니다.
import { buildNuxt, loadNuxt } 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:extend', (config) => {
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)