Home  >  Q&A  >  body text

Add Vuetify to Astro: A step-by-step guide

I'm having trouble adding Vuetify 3 to Astro 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 get the 'Vuetify plugin must be loaded after the vue plugin' error. Not sure how to move on from here. I'm open to all suggestions.

P粉676821490P粉676821490304 days ago574

reply all(1)I'll reply

  • P粉964682904

    P粉9646829042023-12-20 00:45:06

    The configuration in the Astro integration ( @astrojs/vue in this case) is appended to your own Astro configuration, so the vuetify plugin will Start by registering here.

    The workaround is to define your own Astro integration and call < a href="https://docs.astro.build/en/reference/integrations-reference/#updateconfig-option" rel="nofollow noreferrer">updateConfig() Add validation:

    // 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 Vue integration :

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

    reply
    0
  • Cancelreply