vite配置ant自动引入

  1. 安装ant组件,并引入使用

//main.ts中
//ant-design-vue
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
  1. 安装插件

npm install -D unplugin-vue-components unplugin-auto-import
  1. 配置vite.config.ts

import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
//自动导入ui-组件 比如ant-design-vue  element-plus
import Components from "unplugin-vue-components/vite";

//ant-design-vue
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";

//element-plus
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue",'vue-router'],
      dts: "src/auto-import.d.ts",
      resolvers: [AntDesignVueResolver()]
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({ importStyle: true, resolveIcons: true })
      ]
    })
  ]
});

你可能感兴趣的:(vue.js,前端,javascript)