vite.config.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { fileURLToPath, URL } from "node:url";
  2. import vue from "@vitejs/plugin-vue";
  3. import vueDevTools from "vite-plugin-vue-devtools";
  4. import tailwindcss from "@tailwindcss/vite";
  5. import type { ConfigEnv, UserConfig } from "vite";
  6. import { loadEnv } from "vite";
  7. import AutoImport from "unplugin-auto-import/vite";
  8. import Components from "unplugin-vue-components/vite";
  9. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  10. import MotionResolver from "motion-v/resolver";
  11. const root = process.cwd();
  12. // export default defineConfig({
  13. // server: {
  14. // host: "0.0.0.0", // 监听所有网络接口
  15. // port: 5173, // 可选:指定端口
  16. // },
  17. // base: "./",
  18. // plugins: [
  19. // vue(),
  20. // vueDevTools(),
  21. // tailwindcss(),
  22. // AutoImport({
  23. // resolvers: [ElementPlusResolver()],
  24. // }),
  25. // Components({
  26. // dts: true,
  27. // resolvers: [ElementPlusResolver(), MotionResolver()],
  28. // }),
  29. // ],
  30. // resolve: {
  31. // alias: {
  32. // "@": fileURLToPath(new URL("./src", import.meta.url)),
  33. // "@components": fileURLToPath(
  34. // new URL("./src/components", import.meta.url)
  35. // ),
  36. // "@assets": fileURLToPath(new URL("./src/assets", import.meta.url)),
  37. // "@api": fileURLToPath(new URL("./src/api", import.meta.url)),
  38. // "@utils": fileURLToPath(new URL("./src/utils", import.meta.url)),
  39. // "@types": fileURLToPath(new URL("./src/types", import.meta.url)),
  40. // "@stores": fileURLToPath(new URL("./src/stores", import.meta.url)),
  41. // "@hooks": fileURLToPath(new URL("./src/hooks", import.meta.url)),
  42. // },
  43. // },
  44. // });
  45. export default ({ command, mode }: ConfigEnv): UserConfig => {
  46. let env = {} as any;
  47. const isBuild = command === "build";
  48. if (!isBuild) {
  49. env = loadEnv(
  50. process.argv[3] === "--mode" ? process.argv[4] : process.argv[3],
  51. root,
  52. );
  53. } else {
  54. env = loadEnv(mode, root);
  55. }
  56. return {
  57. server: {
  58. host: "0.0.0.0", // 监听所有网络接口
  59. port: 5173, // 可选:指定端口
  60. },
  61. base: "./",
  62. plugins: [
  63. vue(),
  64. vueDevTools(),
  65. tailwindcss(),
  66. AutoImport({
  67. resolvers: [ElementPlusResolver()],
  68. }),
  69. Components({
  70. dts: true,
  71. resolvers: [ElementPlusResolver(), MotionResolver()],
  72. }),
  73. ],
  74. resolve: {
  75. alias: {
  76. "@": fileURLToPath(new URL("./src", import.meta.url)),
  77. "@components": fileURLToPath(
  78. new URL("./src/components", import.meta.url),
  79. ),
  80. "@assets": fileURLToPath(new URL("./src/assets", import.meta.url)),
  81. "@api": fileURLToPath(new URL("./src/api", import.meta.url)),
  82. "@utils": fileURLToPath(new URL("./src/utils", import.meta.url)),
  83. "@types": fileURLToPath(new URL("./src/types", import.meta.url)),
  84. "@stores": fileURLToPath(new URL("./src/stores", import.meta.url)),
  85. "@hooks": fileURLToPath(new URL("./src/hooks", import.meta.url)),
  86. },
  87. },
  88. };
  89. };