1. npm install ant-design-vue --save

安装插件

  1. npm install unplugin-vue-components -D

安装less

  1. npm install less -D
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import styleImport, { VantResolve } from "vite-plugin-style-import";
  4. import Components from 'unplugin-vue-components/vite';
  5. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
  6. import path from 'path'
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. server:{
  10. port: 8080,
  11. },
  12. //设置别名
  13. resolve: {
  14. alias: {
  15. '@': path.resolve(__dirname,'./src'),
  16. 'comps': path.resolve(__dirname,'./src/components')
  17. }
  18. },
  19. plugins: [
  20. vue(),
  21. styleImport({
  22. resolves: [VantResolve()],
  23. }),
  24. Components({
  25. resolvers: [AntDesignVueResolver()],
  26. }),
  27. ],
  28. css: {
  29. preprocessorOptions: {
  30. less: {
  31. javascriptEnabled: true,
  32. }
  33. }
  34. },
  35. });

开启less Js运行时

通常未开启时是不能在js中导入less的

  1. css: {
  2. preprocessorOptions: {
  3. less: {
  4. javascriptEnabled: true,
  5. // modifyVars: {
  6. // 'primary-color': '#20C456'
  7. // }
  8. }
  9. }
  10. },