Nuxt Kit 유틸리티는 Nuxt 3, Bridge가 포함된 Nuxt 2, 그리고 Bridge가 없는 Nuxt 2에서도 사용할 수 있습니다. 모듈이 모든 버전과 호환되는지 확인하려면 checkNuxtCompatibility, assertNuxtCompatibility, hasNuxtCompatibility 함수를 사용할 수 있습니다. 이 함수들은 현재 Nuxt 버전이 제공한 제약 조건을 충족하는지 확인합니다. 또한 더 세밀한 확인을 위해 isNuxt2, isNuxt3, getNuxtVersion 함수도 사용할 수 있습니다.
checkNuxtCompatibility현재 Nuxt 버전에 대해 제약 조건이 충족되는지 확인합니다. 충족되지 않으면 메시지 배열을 반환합니다. Nuxt 2 버전에서는 bridge 지원도 함께 확인합니다.
import { checkNuxtCompatibility, defineNuxtModule } from '@nuxt/kit'
export default defineNuxtModule({
async setup (_options, nuxt) {
const issues = await checkNuxtCompatibility({ nuxt: '^2.16.0' }, nuxt)
if (issues.length) {
console.warn('Nuxt compatibility issues found:\n' + issues.toString())
} else {
// do something
}
},
})
function checkNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<NuxtCompatibilityIssues>
constraints: 확인할 버전 및 빌더 제약 조건입니다. 다음 속성을 허용합니다:
| Property | Type | Required | Description |
|---|---|---|---|
nuxt | string | false | semver 형식의 Nuxt 버전입니다. 예를 들어 >=2.15.0 <3.0.0처럼 Node.js 방식으로 버전을 정의할 수 있습니다. |
bridge | Record<string, string | false> | false | vite, webpack, rspack 같은 특정 Nuxt 빌더에 대한 버전 제약 조건을 지정하거나 호환성을 비활성화합니다. 비활성화하려면 false를 사용하세요. |
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.
assertNuxtCompatibility현재 Nuxt 버전에 대해 제약 조건이 충족되는지 단언합니다. 충족되지 않으면 문제 목록을 문자열로 포함한 오류를 던집니다.
function assertNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<true>
constraints: 확인할 버전 및 빌더 제약 조건입니다. 자세한 내용은 checkNuxtCompatibility의 제약 조건 표를 참고하세요.
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.
hasNuxtCompatibility현재 Nuxt 버전에 대해 제약 조건이 충족되는지 확인합니다. 모든 제약 조건이 충족되면 true를 반환하고, 그렇지 않으면 false를 반환합니다. Nuxt 2 버전에서는 bridge 지원도 함께 확인합니다.
import { defineNuxtModule, hasNuxtCompatibility } from '@nuxt/kit'
export default defineNuxtModule({
async setup (_options, nuxt) {
const usingNewPostcss = await hasNuxtCompatibility({ nuxt: '^2.16.0' }, nuxt)
if (usingNewPostcss) {
// do something
} else {
// do something else
}
},
})
function hasNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<boolean>
constraints: 확인할 버전 및 빌더 제약 조건입니다. 자세한 내용은 checkNuxtCompatibility의 제약 조건 표를 참고하세요.
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.
isNuxtMajorVersion현재 Nuxt 인스턴스가 지정된 메이저 버전인지 확인합니다.
import { defineNuxtModule, isNuxtMajorVersion } from '@nuxt/kit'
export default defineNuxtModule({
setup () {
if (isNuxtMajorVersion(3)) {
// do something for Nuxt 3
} else {
// do something else for other versions
}
},
})
function isNuxtMajorVersion (major: number, nuxt?: Nuxt): boolean
major: 확인할 메이저 버전입니다.
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.
isNuxt3현재 Nuxt 버전이 3.x인지 확인합니다.
isNuxtMajorVersion(2, nuxt)를 사용하세요. 이는 @nuxt/kit v5 또는 향후 메이저 버전에서 제거될 수 있습니다.function isNuxt3 (nuxt?: Nuxt): boolean
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.
isNuxt2현재 Nuxt 버전이 2.x인지 확인합니다.
isNuxtMajorVersion(2, nuxt)를 사용하세요. 이는 @nuxt/kit v5 또는 향후 메이저 버전에서 제거될 수 있습니다.function isNuxt2 (nuxt?: Nuxt): boolean
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.
getNuxtVersion현재 Nuxt 버전을 반환합니다.
function getNuxtVersion (nuxt?: Nuxt): string
nuxt: Nuxt 인스턴스입니다. 제공되지 않으면 useNuxt() 호출을 통해 컨텍스트에서 가져옵니다.