Files
gil-wiki/reference/3.guide/5.recipes/2.vite-plugin.md
gil 5f664546cf feat: 위키 저장소 초기 커밋
- CLAUDE.md 운영 규칙
- wiki/ 정리된 지식 페이지 (Nuxt + Claude Code)
- raw/ 원본 자료
- reference/ Nuxt 4.x 공식 문서

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 00:31:51 +09:00

2.6 KiB

navigation.title, title, description
navigation.title title description
Vite Plugins Using Vite Plugins in Nuxt Learn how to integrate Vite plugins into your Nuxt project.

While Nuxt modules offer extensive functionality, sometimes a specific Vite plugin might meet your needs more directly.

First, we need to install the Vite plugin, for our example, we'll use @rollup/plugin-yaml:

::code-group{sync="pm"}

npm install @rollup/plugin-yaml
yarn add @rollup/plugin-yaml
pnpm add @rollup/plugin-yaml
bun add @rollup/plugin-yaml
deno add npm:@rollup/plugin-yaml

::

Next, we need to import and add it to our nuxt.config.ts file:

import yaml from '@rollup/plugin-yaml'

export default defineNuxtConfig({
  vite: {
    plugins: [
      yaml(),
    ],
  },
})

Now we installed and configured our Vite plugin, we can start using YAML files directly in our project.

For example, we can have a config.yaml that stores configuration data and import this data in our Nuxt components:

::code-group

greeting: "Hello, Nuxt with Vite!"
<script setup>
import config from '~/data/hello.yaml'
</script>

<template>
  <h1>{{ config.greeting }}</h1>
</template>

::

Using Vite Plugins in Nuxt Modules

If you're developing a Nuxt module and need to add Vite plugins, you should use the addVitePlugin utility:

import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import yaml from '@rollup/plugin-yaml'

export default defineNuxtModule({
  setup () {
    addVitePlugin(yaml())
  },
})

For environment-specific plugins in Nuxt 5+, use the applyToEnvironment() method:

import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'

export default defineNuxtModule({
  setup () {
    addVitePlugin(() => ({
      name: 'my-client-plugin',
      applyToEnvironment (environment) {
        return environment.name === 'client'
      },
      // Plugin configuration
    }))
  },
})

::important If you're writing code that needs to access resolved Vite configuration, you should use the config and configResolved hooks within your Vite plugin, rather than using Nuxt's vite:extend, vite:extendConfig and vite:configResolved. ::

::read-more{to="/docs/4.x/api/kit/builder#addviteplugin"} Read more about addVitePlugin in the Nuxt Kit documentation. ::