vite.config.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineConfig, normalizePath, Plugin, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import ViteComponents from "unplugin-vue-components/vite";
  4. import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
  5. const viteEnv = loadEnv("development", process.cwd());
  6. const SERVER_URL = viteEnv.VITE_APP_PROXY_URL;
  7. console.log("SERVER_URL:", SERVER_URL);
  8. const path = require("path");
  9. function mockDevLogin(): Plugin {
  10. return {
  11. name: "mockDevLogin",
  12. apply: "build",
  13. load(id) {
  14. if (id === normalizePath(path.resolve(__dirname, "src/devLogin.ts"))) {
  15. return `export const initLogin = () => {}`;
  16. }
  17. },
  18. };
  19. }
  20. // https://vitejs.dev/config/
  21. export default defineConfig({
  22. base: "./",
  23. plugins: [
  24. vue({
  25. reactivityTransform: true,
  26. }),
  27. ViteComponents({
  28. resolvers: [AntDesignVueResolver()],
  29. dts: true,
  30. }),
  31. mockDevLogin(),
  32. ],
  33. server: {
  34. port: 8059,
  35. // strictPort: true,
  36. fs: {
  37. strict: true,
  38. allow: ["./"],
  39. },
  40. proxy: {
  41. "/api/": {
  42. target: SERVER_URL,
  43. changeOrigin: true,
  44. // rewrite: (path) => path.replace(/^\/api/, ""),
  45. },
  46. },
  47. },
  48. resolve: {
  49. alias: [{ find: "@", replacement: path.resolve(__dirname, "./src") }],
  50. extensions: [".js", ".mjs", ".ts", ".vue", ".json", ".scss", ".css"],
  51. },
  52. build: {
  53. ssr: false,
  54. commonjsOptions: { include: [] },
  55. },
  56. optimizeDeps: {
  57. disabled: false,
  58. },
  59. // define: {
  60. // __VUE_PROD_DEVTOOLS__: true, // no effect
  61. // },
  62. });