3

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.

tony19
  • 125,647
  • 18
  • 229
  • 307
  • 1
    Having the same issue! Just found this example in the Astro discord: [https://stackblitz.com/edit/github-vjbdds](https://stackblitz.com/edit/github-vjbdds) ... worked for me! – thatladgavin Jan 09 '23 at 18:31

1 Answers1

1

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(),
  ],
})
tony19
  • 125,647
  • 18
  • 229
  • 307
  • 1
    Makes sense, thanks. This changes the error to something related to Vuetify. I guess I'm gonna have to wait for the community to build or document the process before I can use Vuetify in Astro. – Cesar Martinez Dominguez Aug 29 '22 at 10:58
  • This solution did work except that the CSS aren't loading properly. Especially in the console it says vars are not set. Will have to look for a workaround. – knkbga May 14 '23 at 05:49