vite.config.ts 1.6 KB

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