首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加ant-design-vue时的NUXT 3模块错误

添加ant-design-vue时的NUXT 3模块错误
EN

Stack Overflow用户
提问于 2022-06-09 06:07:36
回答 1查看 1.1K关注 0票数 1

我正在尝试将Ant Design 作为模块添加到Nuxt3项目中。

代码语言:javascript
复制
    import { fileURLToPath } from "node:url"
    import { defineNuxtModule } from "@nuxt/kit"
    export default defineNuxtModule({
      setup (_, nuxt) {
        nuxt.options.css.push("ant-design-vue/dist/antd.css")
      },
      hooks: {
        "components:dirs" (dirs) {
          dirs.push({
            path: fileURLToPath( new URL('../node_modules/ant-design-vue/lib', import.meta.url) ),
            pattern: '*/index.js',
            prefix: 'a',
          })
        }
      }
    })

但它给出了一个错误:

默认的加载程序只支持格式为: file、data的URL。在Windows上,绝对路径必须是有效文件://URL。接收协议'c:'

我试图通过path.resolve(__dirname, '...')使用,但没有成功

节点: v16.15.0 Nuxt: 3.0.0-rc.3 ant-design-vue: 3.2.5

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-10 06:07:33

经过两天的研究,终于得到了解决方案。

在NUXT 3项目中添加ant-design-vue和图标

  1. 安装deps

代码语言:javascript
复制
npm i ant-design-vue @ant-design/icons-vue unplugin-vue-components --save

  1. 将其添加到nuxt.config文件

代码语言:javascript
复制
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';

export default defineNuxtConfig({
 
  vite: {
    plugins: [
      Components({
        // add option {resolveIcons: true} as parameter for resolving problem with icons
        resolvers: [AntDesignVueResolver({resolveIcons: true})],
      }),
    ],
    // @ts-expect-error: Missing ssr key
    ssr: {
      noExternal: ['moment', 'compute-scroll-into-view', 'ant-design-vue','@ant-design/icons-vue'],
    },  
  },
})

auto-importing的魔力,

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72555420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档