예시

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)