登录  /  注册
将 Vuetify 添加到 Astro:分步指南
P粉676821490
P粉676821490 2023-12-19 09:35:08
[Vue.js讨论组]

使用 Vue 集成时,我在将 Vuetify 3 添加到 Astro 时遇到问题。 这是我到目前为止所拥有的:

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()],
  },
});

我收到 'Vuetify 插件必须在 vue 插件之后加载' 错误。 不知道如何从这里继续前进。我愿意接受所有建议。

P粉676821490
P粉676821490

全部回复(1)
P粉964682904

Astro 集成中的配置 ( @astrojs/vue 在本例中)被附加到您自己的 Astro 配置中,因此 vuetify 插件将首先在此处注册。

解决方法是定义您自己的 Astro 集成,调用 updateConfig() 添加验证:

// 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()],
          },
        });
      },
    },
  }
}

并在 Vue 集成之后安装它:

// astro.config.mjs
export default defineConfig({
  integrations: [
    vue(),
    vuetify(),
  ],
})
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号