vite.config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import path from "path";
  2. import { defineConfig, loadEnv } from "vite";
  3. import vue from "@vitejs/plugin-vue";
  4. import vueJsx from "@vitejs/plugin-vue-jsx";
  5. import Components from "unplugin-vue-components/vite";
  6. import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
  7. import vueSetupExtend from "unplugin-vue-setup-extend-plus/vite";
  8. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  9. const resolvePath = (...args: any[]) => {
  10. return path.resolve(__dirname, ...args);
  11. };
  12. const env = loadEnv("development", process.cwd(), "");
  13. // https://vitejs.dev/config/
  14. export default defineConfig({
  15. plugins: [
  16. vue({ reactivityTransform: true }),
  17. vueJsx({}),
  18. Components({ resolvers: [AntDesignVueResolver({ importStyle: false })] }),
  19. createSvgIconsPlugin({
  20. iconDirs: [resolvePath("src/assets/icons")],
  21. symbolId: "icon-[dir]-[name]",
  22. customDomId: "__svg__icons__dom__",
  23. }),
  24. vueSetupExtend(),
  25. ],
  26. resolve: {
  27. extensions: [".vue", ".js", ".ts", ".jsx", ".tsx", ".json"],
  28. alias: [
  29. { find: "@", replacement: resolvePath("src") },
  30. { find: "@api", replacement: resolvePath("src/apis") },
  31. { find: "@imgs", replacement: resolvePath("src/assets/images") },
  32. { find: "@hooks", replacement: resolvePath("src/hooks") },
  33. ],
  34. },
  35. css: {
  36. preprocessorOptions: {
  37. less: {
  38. additionalData(content, context) {
  39. if (context.includes("antd.theme.less")) {
  40. return (
  41. content +
  42. `\r\n@import "${resolvePath("src/assets/less/var.less")}";`
  43. );
  44. }
  45. return (
  46. `@import "${resolvePath("src/assets/less/var.less")}";\r\n` +
  47. content
  48. );
  49. },
  50. javascriptEnabled: true,
  51. },
  52. },
  53. },
  54. server: {
  55. port: 9020,
  56. proxy: {
  57. "^/api": {
  58. target: env.VITE_APP_DEV_PROXY,
  59. },
  60. },
  61. },
  62. });