Vite集成antdv并配置按需加载

官网文档

安装antdv

yarn add ant-design-vue@next

Vite配置按需导入

  1. 安装vite按需导入插件 yarn add -D unplugin-vue-components;vite-plugin-components插件已renamed to unplugin-vue-components
  2. 配置vite.config.js:

    import { defineConfig } from 'vite'
    import vue from '@vitejs/plugin-vue'
    import Components from 'unplugin-vue-components/vite'
    import {AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
    
    // https://vitejs.dev/config/
    export default defineConfig({
    plugins: [
     vue(),
     Components({
     resolvers: [
       AntDesignVueResolver()
     ],
     dts: true, // enabled by default if `typescript` is installed
     })
    ]
    })
    
  3. 组件无需导入使用(import HelloWorld被注释)

    
    
    
    
    

你可能感兴趣的