본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

v4로 마이그레이션

원문 보기 위키 갱신

v4로 마이그레이션 (Migration to v4)

Nuxt UI v3에서 v4로 애플리케이션을 마이그레이션하는 방법을 다루는 종합 가이드예요. Nuxt UI와 Nuxt UI Pro의 통합, 이름 변경된 컴포넌트, AI SDK 변경 사항을 다룹니다.

출처: Nuxt UI

본문

Nuxt UI v3에서 v4로 애플리케이션을 마이그레이션하는 종합 가이드예요.

Nuxt UI v4는 중요한 이정표를 의미합니다: Nuxt UI와 Nuxt UI Pro가 완전히 오픈소스이고 무료인 단일 라이브러리로 통합되었어요. 이제 @nuxt/ui 패키지에서 사용 가능한 125+ 개의 프로덕션 준비 컴포넌트에 접근할 수 있습니다.

[!NOTE]

Nuxt UI v4는 일부 의존성 때문에 Nuxt 4.1 이상을 요구해요. Nuxt UI v4로 마이그레이션하기 전에 꼭 업그레이드하세요.

이 가이드는 애플리케이션을 v3에서 v4로 마이그레이션하는 단계별 지침을 제공해요.

프로젝트 마이그레이션 (Migrate your project)

Nuxt UI Pro에서

  1. package.json에서 @nuxt/ui-pro를 @nuxt/ui로 바꾸세요:
pnpm remove @nuxt/ui-pro
pnpm add @nuxt/ui tailwindcss
yarn remove @nuxt/ui-pro
yarn add @nuxt/ui tailwindcss
npm uninstall @nuxt/ui-pro
npm install @nuxt/ui tailwindcss
bun remove @nuxt/ui-pro
bun add @nuxt/ui tailwindcss

Nuxt:

  1. nuxt.config.ts에서 @nuxt/ui-pro를 @nuxt/ui로 바꾸세요:
export default defineNuxtConfig({
  modules: [
-   '@nuxt/ui-pro',
+   '@nuxt/ui'
  ]
})

Vue:

  1. vite.config.ts에서 @nuxt/ui-pro를 @nuxt/ui로 바꾸세요:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
- import uiPro from '@nuxt/ui-pro/vite'
+ import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
-   uiPro({
+   ui({
      ui: {
        colors: {
          primary: 'green',
          neutral: 'slate'
        }
      }
    })
  ]
})

Nuxt:

  1. app.config.ts에서 uiPro 대신 ui 키를 사용하세요:
export default defineAppConfig({
  ui: {
    colors: {
      primary: 'green',
      neutral: 'slate'
    },
+   pageCard: {
+     slots: {
+       root: 'rounded-xl',
+     }
+   }
  },
- uiPro: {
-   pageCard: {
-     slots: {
-       root: 'rounded-xl',
-     }
-   }
- }
})

Vue:

  1. vite.config.ts에서 uiPro 대신 ui 키를 사용하세요:
export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        colors: {
          primary: 'green',
          neutral: 'slate'
        },
+       pageCard: {
+         slots: {
+           root: 'rounded-xl',
+         }
+       }
      },
-     uiPro: {
-       pageCard: {
-         slots: {
-           root: 'rounded-xl',
-         }
-       }
-     }
    })
  ]
})
  1. CSS에서 @nuxt/ui-pro를 @nuxt/ui로 바꾸세요:

Nuxt:

@import "tailwindcss";
- @import "@nuxt/ui-pro";
+ @import "@nuxt/ui";

[!WARNING]

Nuxt 4로의 업그레이드를 Nuxt UI v4와 동시에 진행한다면 @source 지시문을 새 디렉터리 구조에 맞게 업데이트하세요.

@import "tailwindcss";
@import "@nuxt/ui";

- @source "../../content/**/*";
+ @source "../../../content/**/*";

Vue:

@import "tailwindcss";
- @import "@nuxt/ui-pro";
+ @import "@nuxt/ui";
  1. 임포트에서 @nuxt/ui-pro를 @nuxt/ui로 바꾸세요:
- import type { BannerProps } from '@nuxt/ui-pro'
+ import type { BannerProps } from '@nuxt/ui'

Nuxt UI에서

  1. Nuxt UI v3에서 업그레이드할 때는 v4로 업데이트만 하면 됩니다:
pnpm add @nuxt/ui tailwindcss
yarn add @nuxt/ui tailwindcss
npm install @nuxt/ui tailwindcss
bun add @nuxt/ui tailwindcss

v3에서의 변경 사항 (Changes from v3)

Nuxt UI v4로 업그레이드한 후 다음의 중요한 변경 사항을 참고하세요:

ButtonGroup 이름 변경

ButtonGroup 컴포넌트가 FieldGroup으로 이름이 바뀌었어요:

<template>
- <UButtonGroup>
+ <UFieldGroup>
    <UButton label="Button" />
    <UButton icon="i-lucide-chevron-down" />
+ </UFieldGroup>
- </UButtonGroup>
</template>

PageMarquee 이름 변경

PageMarquee 컴포넌트가 Marquee로 이름이 바뀌었어요:

<template>
- <UPageMarquee :items="items" />
+ <UMarquee :items="items" />
</template>

PageAccordion 제거

PageAccordion 컴포넌트가 Accordion으로 대체되며 제거되었어요:

<template>
- <UPageAccordion
+ <UAccordion
    :items="items"
+   :unmount-on-hide="false"
+   :ui="{ trigger: 'text-base', body: 'text-base text-muted' }"
  />
</template>

[!NOTE]

PageAccordion 컴포넌트는 unmount-on-hide를 false로 설정하고 ui prop을 커스터마이즈하는 래퍼였어요.

model 수정자 이름 변경

Input, InputNumber, Textarea에서 사용하는 modelModifiers 형태가 v4에서 바뀌었어요:

  1. nullify 수정자가 nullable로 이름이 바뀌었어요(빈/공백 값을 null로 변환).
  2. optional 수정자가 새로 추가되었어요(빈/공백 값을 undefined로 변환).
- <UInput v-model.nullify="value" />
+ <UInput v-model.nullable="value" />
- <UTextarea v-model="value" :model-modifiers="{ nullify: true }" />
+ <UTextarea v-model="value" :model-modifiers="{ nullable: true }" />

빈 값을 null로 원하면 nullable을, 값이 없을 때 undefined를 선호하면 optional을 사용하세요.

Form 컴포넌트 변경

Form 컴포넌트는 v4에서 더 나은 상태 관리와 중첩 폼 처리로 개선되었어요. 알아둬야 할 주요 변경 사항은 다음과 같습니다:

  1. 스키마 변환은 @submit 데이터에만 적용되며 더 이상 폼의 상태를 변경하지 않아요. 이렇게 하면 예측 가능성이 높아지고 예기치 않은 상태 변경을 방지합니다.
  2. 중첩 폼은 nested prop을 사용해 명시적으로 활성화해야 해요. 이렇게 하면 컴포넌트 동작이 더 명확해지고 실수로 중첩 폼이 만들어지는 것을 방지합니다.
  3. 중첩 폼은 이제 name prop을 제공해야 하며(UFormField처럼) 부모 폼에서 상태를 자동으로 상속받습니다.
<template>
  <UForm :state="state" :schema="schema" @submit="onSubmit">
    <UFormField label="Customer" name="customer">
      <UInput v-model="state.customer" placeholder="Wonka Industries" />
    </UFormField>

    <div v-for="(item, index) in state.items" :key="index">
      <UForm
-       :state="item"
+       :name="`items.${index}`"
        :schema="itemSchema"
+       nested
      >
        <UFormField :label="!index ? 'Description' : undefined" name="description">
          <UInput v-model="item.description" />
        </UFormField>
        <UFormField :label="!index ? 'Price' : undefined" name="price">
          <UInput v-model="item.price" type="number" />
        </UFormField>
      </UForm>
    </div>
  </UForm>
</template>

폐기된 유틸리티 제거

이전에 Nuxt UI Pro에 있던 일부 Nuxt Content 유틸리티가 v4에서 제거되었어요:

  • findPageBreadcrumb
  • findPageHeadline

이것들은 이제 Nuxt Content가 완전히 제공해요. 임포트와 사용처를 그에 맞게 업데이트하세요.

- import { findPageHeadline } from '@nuxt/ui-pro/utils/content'
+ import { findPageHeadline } from '@nuxt/content/utils'

- import { findPageBreadcrumb } from '@nuxt/ui-pro/utils/content'
+ import { findPageBreadcrumb } from '@nuxt/content/utils'

AI SDK 마이그레이션 (선택 사항)

이 섹션은 AI SDK와 채팅 컴포넌트(ChatMessage, ChatMessages, ChatPrompt, ChatPromptSubmit, ChatPalette)를 사용하는 경우에만 적용돼요. AI 기능을 사용하지 않는다면 이 섹션을 건너뛰어도 됩니다.

  1. package.json에서 @ai-sdk/vue와 ai 의존성을 업데이트하고 Comark을 추가하세요(AI 응답을 스트리밍 Markdown으로 렌더링하는 @nuxtjs/mdc를 대체):

Nuxt:

{
  "dependencies": {
-   "@ai-sdk/vue": "^1.2.x",
+   "@ai-sdk/vue": "^4.0.x",
-   "ai": "^4.3.x",
+   "ai": "^7.0.x",
+   "@comark/nuxt": "latest"
  }
}

모듈에 @comark/nuxt를 추가하세요:

export default defineNuxtConfig({
  modules: [
    '@nuxt/ui',
+   '@comark/nuxt'
  ]
})

Vue:

{
  "dependencies": {
-   "@ai-sdk/vue": "^1.2.x",
+   "@ai-sdk/vue": "^4.0.x",
-   "ai": "^4.3.x",
+   "ai": "^7.0.x",
+   "@comark/vue": "latest"
  }
}
  1. useChat 컴포저블 API가 바뀌었어요: input과 handleSubmit이 sendMessage로 대체되었고, messages는 직접 설정하는 ref가 되었어요:
<script setup lang="ts">
  import { useChat } from '@ai-sdk/vue'

- const { messages, input, handleSubmit, status, error, reload, setMessages } = useChat()
+ const { messages, status, error, sendMessage, regenerate, stop } = useChat()
+ const input = ref('')

+ function handleSubmit() {
+   sendMessage({ text: input.value })
+   input.value = ''
+ }
</script>
  1. 메시지는 이제 content 대신 parts를 사용해요:
// When manually creating messages
- setMessages([{
+ messages.value = [{
  id: '1',
  role: 'user',
- content: 'Hello world'
+ parts: [{ type: 'text', text: 'Hello world' }]
- }])
+ }]

// In templates
<template>
- <UChatMessage :content="message.content" />
+ <UChatMessage :parts="message.parts" />
</template>
  1. 일부 메서드의 이름이 바뀌었어요:
// Regenerate the last message
- reload()
+ regenerate()
  1. parts 기반 렌더링을 위해 <MDC>를 <Markdown>으로 바꾸세요. Markdown 컴포넌트는 스트리밍 Markdown을 위해 특별히 설계되어, AI에서 도착하는 대로 토큰을 점진적으로 렌더링해요. AI SDK 헬퍼와 @nuxt/ui/utils/ai의 isPartStreaming 유틸리티를 사용하세요.

[!NOTE]

shiki 플러그인을 사용할 때 다크 모드 지원을 위해 스타일시트에 다음 CSS를 추가하세요:

html.dark .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

Nuxt:

<script setup lang="ts">
import { isReasoningUIPart, isTextUIPart } from 'ai'
import { isPartStreaming } from '@nuxt/ui/utils/ai'
import shiki from '@comark/nuxt/plugins/shiki'

const plugins = [shiki()]
</script>

<template>
  <UChatMessages :messages="messages" :status="status">
    <template #content="{ message }">
      <template v-for="(part, index) in message.parts" :key="`${message.id}-${part.type}-${index}`">
        <UChatReasoning
          v-if="isReasoningUIPart(part)"
          :text="part.text"
          :streaming="isPartStreaming(part)"
        >
          <Markdown
            :value="part.text"
            :streaming="isPartStreaming(part)"
            :plugins="plugins"
            class="*:first:mt-0 *:last:mb-0"
          />
        </UChatReasoning>

        <template v-else-if="isTextUIPart(part)">
          <Markdown
            v-if="message.role === 'assistant'"
            :value="part.text"
            :streaming="isPartStreaming(part)"
            :plugins="plugins"
            class="*:first:mt-0 *:last:mb-0"
          />
          <p v-else-if="message.role === 'user'" class="whitespace-pre-wrap">
            {{ part.text }}
          </p>
        </template>
      </template>
    </template>
  </UChatMessages>
</template>

Vue:

<script setup lang="ts">
import { isReasoningUIPart, isTextUIPart } from 'ai'
import { isPartStreaming } from '@nuxt/ui/utils/ai'
import { Markdown } from '@comark/vue'
import shiki from '@comark/vue/plugins/shiki'

const plugins = [shiki()]
</script>

<template>
  <UChatMessages :messages="messages" :status="status">
    <template #content="{ message }">
      <template v-for="(part, index) in message.parts" :key="`${message.id}-${part.type}-${index}`">
        <UChatReasoning
          v-if="isReasoningUIPart(part)"
          :text="part.text"
          :streaming="isPartStreaming(part)"
        >
          <Markdown
            :value="part.text"
            :streaming="isPartStreaming(part)"
            :plugins="plugins"
            class="*:first:mt-0 *:last:mb-0"
          />
        </UChatReasoning>

        <template v-else-if="isTextUIPart(part)">
          <Markdown
            v-if="message.role === 'assistant'"
            :value="part.text"
            :streaming="isPartStreaming(part)"
            :plugins="plugins"
            class="*:first:mt-0 *:last:mb-0"
          />
          <p v-else-if="message.role === 'user'" class="whitespace-pre-wrap">
            {{ part.text }}
          </p>
        </template>
      </template>
    </template>
  </UChatMessages>
</template>

[!NOTE] See: https://ai-sdk.dev/docs/migration-guides/migration-guide-7-0

AI SDK 변경 사항에 대해 더 자세히 알고 싶다면 공식 AI SDK 마이그레이션 가이드를 확인하세요.

[!TIP] See: https://github.com/nuxt/ui/pull/6636

자세한 마이그레이션 참조를 위해 AI SDK v7 업그레이드 PR의 모든 변경 사항을 확인하세요.

더 알아보기 (Learn more)