Skip to content

Commit e744668

Browse files
authored
feat: add support for Vuetify 3.4 (#151)
* feat: add support for Vuetify 3.4 * chore: cleanup
1 parent 86246cd commit e744668

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

src/module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
isNuxt3,
77
useLogger,
88
} from '@nuxt/kit'
9+
import { getPackageInfo } from 'local-pkg'
910
import { version } from '../package.json'
1011
import type { ModuleOptions } from './types'
1112
import type { VuetifyNuxtContext } from './utils/config'
@@ -40,6 +41,10 @@ export default defineNuxtModule<ModuleOptions>({
4041
if (!isNuxt3(nuxt))
4142
logger.error(`Cannot support nuxt version: ${getNuxtVersion(nuxt)}`)
4243

44+
const vuetifyPkg = await getPackageInfo('vuetify')
45+
const versions = vuetifyPkg?.version?.split('.').map(v => Number.parseInt(v))
46+
const vuetify3_4 = versions && versions.length > 1 && versions[0] >= 3 && versions[1] >= 4
47+
4348
const ctx: VuetifyNuxtContext = {
4449
logger,
4550
resolver: createResolver(import.meta.url),
@@ -55,6 +60,7 @@ export default defineNuxtModule<ModuleOptions>({
5560
ssrClientHints: undefined!,
5661
componentsPromise: undefined!,
5762
labComponentsPromise: undefined!,
63+
vuetify3_4,
5864
}
5965

6066
await load(options, nuxt, ctx)

src/utils/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface VuetifyNuxtContext {
2525
ssrClientHints: ResolvedClientHints
2626
componentsPromise: Promise<VuetifyComponentsImportMap>
2727
labComponentsPromise: Promise<VuetifyComponentsImportMap>
28+
vuetify3_4?: boolean
2829
}
2930

3031
export async function loadVuetifyConfiguration<U extends ExternalVuetifyOptions>(

src/vite/vuetify-configuration-plugin.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ async function buildConfiguration(ctx: VuetifyNuxtContext) {
182182
if (typeof labComponents === 'boolean') {
183183
config.imports.push('import * as labsComponents from \'vuetify/labs/components\'')
184184
config.labComponents.add('*')
185-
addDatePicker = false
185+
if (ctx.vuetify3_4 === false)
186+
addDatePicker = false
186187
}
187188
else if (typeof labComponents === 'string') {
188189
useLabComponents.push(labComponents)
@@ -217,25 +218,38 @@ async function buildConfiguration(ctx: VuetifyNuxtContext) {
217218
config.labComponents.add(component)
218219
})
219220

220-
if (dateOptions && !config.labComponents.has('VDatePicker')) {
221+
if (ctx.vuetify3_4 === false && dateOptions && !addDatePicker) {
221222
const entry = componentsToImport.get('VDatePicker')
222223
if (entry) {
223224
entry.push('VDatePicker')
224225
config.labComponents.add('VDatePicker')
226+
addDatePicker = false
225227
}
226228
}
227229

228230
componentsToImport.forEach((componentsArray, from) => {
229231
config.imports.push(`import {${componentsArray.join(',')}} from 'vuetify/labs/${from}'`)
230232
})
231-
addDatePicker = !config.labComponents.has('VDatePicker')
232233
}
233234
}
234235

235236
// include date picker only when needed
236237
if (dateOptions && addDatePicker) {
237-
config.imports.push('import {VDatePicker} from \'vuetify/labs/VDatePicker\'')
238-
config.labComponents.add('VDatePicker')
238+
let warn = true
239+
if (typeof ctx.vuetify3_4 === 'boolean') {
240+
warn = false
241+
if (ctx.vuetify3_4) {
242+
// @ts-expect-error VDatePicker is on labs when version < 3.4
243+
config.components.add('VDatePicker')
244+
config.imports.push('import {VDatePicker} from \'vuetify/components/VDatePicker\'')
245+
}
246+
else {
247+
config.labComponents.add('VDatePicker')
248+
config.imports.push('import {VDatePicker} from \'vuetify/labs/VDatePicker\'')
249+
}
250+
}
251+
252+
warn && logger.warn('Unable to load Vuetify version from package.json, add VDatePicker to components or labComponents')
239253
}
240254

241255
// components entry

src/vite/vuetify-date-configuration-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export function dateConfiguration() {
2727
const { adapter: _adapter, ...newDateOptions } = ctx.vuetifyOptions.date ?? {}
2828

2929
const imports = ctx.dateAdapter === 'vuetify'
30-
? 'import { VuetifyDateAdapter } from \'vuetify/labs/date/adapters/vuetify\''
30+
? ctx.vuetify3_4 === true
31+
? ''
32+
: 'import { VuetifyDateAdapter } from \'vuetify/labs/date/adapters/vuetify\''
3133
: ctx.dateAdapter === 'custom'
3234
? ''
3335
: `import Adapter from '@date-io/${ctx.dateAdapter}'`
@@ -48,7 +50,7 @@ export function dateConfiguration() {
4850
}
4951

5052
function buildAdapter() {
51-
if (ctx.dateAdapter === 'custom')
53+
if (ctx.dateAdapter === 'custom' || (ctx.dateAdapter === 'vuetify' && ctx.vuetify3_4 === true))
5254
return ''
5355

5456
if (ctx.dateAdapter === 'vuetify')

0 commit comments

Comments
 (0)