Skip to content

Commit

Permalink
chore: include vuetify in types and update plugin hook signature (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Jul 1, 2023
1 parent 552627f commit d0e3bfd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
8 changes: 5 additions & 3 deletions playground/plugins/vuetify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('vuetify:configuration', (vuetifyOptions) => {
// eslint-disable-next-line no-console
console.log('vuetify:plugin:hook', vuetifyOptions)
nuxtApp.hook('vuetify:configuration', (isDev, vuetifyOptions) => {
if (process.client && isDev) {
// eslint-disable-next-line no-console
console.log('vuetify:plugin:hook', vuetifyOptions)
}
})
})
4 changes: 1 addition & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default defineNuxtModule<ModuleOptions>({

nuxt.hook('prepare:types', ({ references }) => {
references.push({ types: 'vuetify-nuxt-module/configuration' })
references.push({ types: 'vuetify/components' })
references.push({ types: 'vuetify' })
})

nuxt.hook('vite:extendConfig', (viteInlineConfig) => {
Expand Down Expand Up @@ -105,8 +105,6 @@ export default defineNuxtModule<ModuleOptions>({
addPluginTemplate({
src: resolver.resolve(runtimeDir, 'templates/plugin.mts'),
write: nuxt.options.dev || writePlugin,
}, {
append: true,
})
},
})
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/templates/plugin.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default defineNuxtPlugin({
const nuxtApp = useNuxtApp()
const options = vuetifyConfiguration()

await nuxtApp.hooks.callHook('vuetify:configuration', options)
await nuxtApp.hooks.callHook('vuetify:configuration', isDev, options)

const vuetify = createVuetify(vuetifyConfiguration())

nuxtApp.vueApp.use(vuetify)

if (!process.server && isDev) {
if (process.client && isDev) {
// eslint-disable-next-line no-console
console.log('Vuetify 3 initialized', vuetify)
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export interface ModuleOptions {

declare module '#app' {
interface RuntimeNuxtHooks {
'vuetify:configuration': (vuetifyOptions: VuetifyOptions) => void
'vuetify:configuration': (isDev: boolean, vuetifyOptions: VuetifyOptions) => Promise<void> | void
}
}
13 changes: 8 additions & 5 deletions src/vuetify-configuration-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export function vuetifyConfigurationPlugin(
vuetifyAppOptions: VuetifyOptions,
) {
const VIRTUAL_VUETIFY_CONFIGURATION = 'virtual:vuetify-configuration'
const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `\0${VIRTUAL_VUETIFY_CONFIGURATION}`
// TODO: ask Daniel Roe, I guess it is some internal nuxt module that shouldn't intercept this
// Nuxt DevTools doesn't shows the virtual when using Vite's default but it does when removing virtual: prefix
// const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `\0${VIRTUAL_VUETIFY_CONFIGURATION}`
const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `/@nuxt-vuetify-configuration/${VIRTUAL_VUETIFY_CONFIGURATION.slice('virtual:'.length)}`

return <Plugin>{
name: 'vuetify:configuration:nuxt',
Expand All @@ -26,16 +29,16 @@ export function vuetifyConfigurationPlugin(
async load(id) {
if (id === RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION) {
const directivesResult = buildDirectives()
const labsComponentsResult = buildLabsComponents()
const labComponentsResult = buildLabComponents()

return `${directivesResult.imports}
${labsComponentsResult.imports}
${labComponentsResult.imports}
export const isDev = ${isDev}
export function vuetifyConfiguration() {
const options = ${JSON.stringify(vuetifyAppOptions)}
${directivesResult.expression}
${labsComponentsResult.expression}
${labComponentsResult.expression}
return options
}
`
Expand All @@ -61,7 +64,7 @@ export function vuetifyConfiguration() {
}
}

function buildLabsComponents() {
function buildLabComponents() {
if (!labComponents)
return <ImportsResult>{ imports: '', expression: '' }

Expand Down

0 comments on commit d0e3bfd

Please sign in to comment.