Skip to content

Commit 5a427fd

Browse files
committed
fix: handle named export in vuetify custom config file
1 parent 4a27170 commit 5a427fd

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

packages/vuetify-nuxt-module/src/utils/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export async function loadVuetifyConfiguration<U extends ExternalVuetifyOptions>
9191
const result = await loader.load()
9292
result.config = result.config?.config === false ? Object.assign(defaults, inlineConfig) : Object.assign(defaults, result.config || inlineConfig)
9393

94+
if (result.config && typeof result.config === 'object' && 'vuetifyOptions' in result.config) {
95+
const nestedOptions = (result.config as any).vuetifyOptions
96+
if (typeof nestedOptions === 'object' && nestedOptions !== null) {
97+
console.warn('[@vuetify/nuxt-module] Detected nested "vuetifyOptions" in your configuration file. This usually happens when using a named export or wrapping options incorrectly. Please export the options directly using "export default".')
98+
Object.assign(result.config, nestedOptions)
99+
delete (result.config as any).vuetifyOptions
100+
}
101+
}
102+
94103
delete result.config.config
95104

96105
return result
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<v-app>
3+
<MyBtn class="my-btn">Click me</MyBtn>
4+
</v-app>
5+
</template>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import MyModule from '../../../src/module'
2+
3+
export default defineNuxtConfig({
4+
modules: [MyModule],
5+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"private": true,
3+
"type": "module"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const vuetifyOptions = {
2+
aliases: {
3+
MyBtn: 'VBtn',
4+
},
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { $fetch, setup } from '@nuxt/test-utils'
3+
import { describe, expect, it } from 'vitest'
4+
5+
describe('vuetify-config-nested', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('fixtures/vuetify-config-nested', import.meta.url)),
8+
})
9+
10+
it('loads vuetify.config.ts with named export and applies configuration', async () => {
11+
const html = await $fetch('/')
12+
// Check if the alias MyBtn was resolved to VBtn (which renders with class v-btn)
13+
expect(html).toContain('v-btn')
14+
expect(html).toContain('my-btn')
15+
})
16+
})

0 commit comments

Comments
 (0)