From b5a1e4b3163315e0b9e839a5910cef146757f1b9 Mon Sep 17 00:00:00 2001 From: Teranode Date: Tue, 13 Dec 2022 20:35:40 +0200 Subject: [PATCH] Import blueprint based on string I'm guessing its runtime issues, but you need to import blueprints in the plugin. I'm certain this also has other implications for other imports. Also updated the types to override the blueprint property to reflect this change --- package.json | 2 +- src/module.ts | 8 +++----- src/runtime/templates/plugin.mjs | 10 ++++++++-- src/types.ts | 8 ++++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index d29e2fd..1f1ea38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nuxt-alt/vuetify", - "version": "1.0.6", + "version": "1.0.8", "description": "An alternative module for setting up Vueitfy 3 with nuxt.", "homepage": "https://github.com/nuxt-alt/vuetify", "author": "Teranode", diff --git a/src/module.ts b/src/module.ts index 8d5fb6a..0679002 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,7 +1,7 @@ import type { ModuleOptions } from './types'; import type { Nuxt } from '@nuxt/schema' import { name, version } from '../package.json'; -import { defineNuxtModule, addPluginTemplate, createResolver, addImports, addTemplate } from '@nuxt/kit'; +import { defineNuxtModule, addPluginTemplate, createResolver, addImports } from '@nuxt/kit'; import vuetify from 'vite-plugin-vuetify' import { defu } from 'defu' @@ -45,7 +45,7 @@ export default defineNuxtModule({ // Vuetify plugin configuration config.plugins = [ ...(config.plugins || []), - vuetify(options.pluginOptions), + vuetify(options.pluginOptions) as typeof config.plugins, ] config.define = { @@ -74,9 +74,7 @@ export default defineNuxtModule({ addPluginTemplate({ src: resolve('./runtime/templates/plugin.mjs'), filename: 'vuetify.plugin.mjs', - options: { - options: options.vuetifyOptions - } + options: options.vuetifyOptions }) // Runtime diff --git a/src/runtime/templates/plugin.mjs b/src/runtime/templates/plugin.mjs index 848feee..db17a57 100644 --- a/src/runtime/templates/plugin.mjs +++ b/src/runtime/templates/plugin.mjs @@ -1,10 +1,16 @@ import { defineNuxtPlugin } from '#imports'; import { createVuetify } from '#vuetify'; -const options = JSON.parse('<%= JSON.stringify(options) %>') +const opts = JSON.parse('<%= JSON.stringify(options) %>') + +'<% if (options.blueprint) { %>' +import { <%= options.blueprint %> as blueprint } from 'vuetify/blueprints' +opts.blueprint = blueprint +'<% } %>' export default defineNuxtPlugin(nuxtApp => { - const vuetify = createVuetify(options) + const vuetify = createVuetify(opts) + nuxtApp.vueApp.use(vuetify) return { diff --git a/src/types.ts b/src/types.ts index 578483c..8264334 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,14 +10,18 @@ interface Options { stylesTimeout?: number; } +export interface NuxtVuetifyOptions extends Omit { + blueprint: 'md1' | 'md2' | 'md3' +} + export interface ModuleOptions { - vuetifyOptions?: VuetifyOptions + vuetifyOptions?: NuxtVuetifyOptions pluginOptions?: Options } declare module '#app' { interface NuxtApp { - $vuetify: VuetifyOptions; + $vuetify: NuxtVuetifyOptions; } }