vite.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { defineConfig, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { resolve } from "path";
  4. // import legacy from "@vitejs/plugin-legacy";
  5. import AutoImport from "unplugin-auto-import/vite";
  6. import Components from "unplugin-vue-components/vite";
  7. import { VantResolver } from "@vant/auto-import-resolver";
  8. import { viteMockServe } from "vite-plugin-mock";
  9. export default defineConfig(({ mode }) => {
  10. const env = loadEnv(mode, process.cwd(), "");
  11. return {
  12. // 部署二级目录基础路径
  13. // base: env.VITE_BASE || "/",
  14. base: env.VITE_BASE,
  15. resolve: {
  16. alias: {
  17. "@": resolve(__dirname, "src"),
  18. },
  19. },
  20. server: {
  21. host: "0.0.0.0",
  22. port: 8200,
  23. strictPort: true,
  24. open: true,
  25. cors: true,
  26. proxy: {
  27. "/api": {
  28. target: "http://192.168.10.41:8080",
  29. changeOrigin: true,
  30. // rewrite: (path) => path.replace(new RegExp(`^${envConfig.proxy}`), ''),
  31. },
  32. },
  33. },
  34. build: {
  35. sourcemap: false,
  36. outDir: env.VITE_OUT_DIR,
  37. chunkSizeWarningLimit: 2000,
  38. reportCompressedSize: false,
  39. },
  40. plugins: [
  41. vue(),
  42. // legacy({
  43. // targets: ["defaults", "not IE 11"],
  44. // }),
  45. viteMockServe(),
  46. AutoImport({
  47. resolvers: [VantResolver()],
  48. }),
  49. Components({
  50. resolvers: [VantResolver()],
  51. }),
  52. ],
  53. };
  54. });