How to add Vuetify to astro?

Viewed 164

I'm having trouble adding Vuetify 3 to Astro when using the Vue integration. This is what I have so far:

import { defineConfig } from 'astro/config';

import vue from '@astrojs/vue';

import vuetify from 'vite-plugin-vuetify';

// https://astro.build/config
export default defineConfig({
  integrations: [vue()],
  vite: {
    ssr: {
      noExternal: ['vuetify'],
    },
    plugins: [vuetify()],
  },
});

I'm getting the 'Vuetify plugin must be loaded after the vue plugin' error. Don't know how to move on from here. I'm open to all suggestions.

1 Answers

The configs in the Astro integrations (@astrojs/vue in this case) are appended to your own Astro config, so the vuetify plugin would be registered first here.

A workaround is to define your own Astro integration that calls updateConfig() to add Vuetify:

// astro.config.mjs
import vuetifyPlugin from 'vite-plugin-vuetify';

/**
 * Vuetify integration for Astro
 * @param {import('astro/config').Options} options
 * @returns {import('astro/config').AstroIntegration}
 */
function vuetify(options) {
  return {
    name: 'my-astro-vuetify-integration',
    hooks: {
      'astro:config:setup': ({ updateConfig }) => {
        updateConfig({
          vite: {
            ssr: {
              noExternal: ['vuetify'],
            },
            plugins: [vuetifyPlugin()],
          },
        });
      },
    },
  }
}

And install it after the Vue integration:

// astro.config.mjs
export default defineConfig({
  integrations: [
    vue(),
    vuetify(),
  ],
})
Related