vite.config.ts 1.7 KB

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