vite.config.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { defineConfig } from "vite";
  2. import react from "@vitejs/plugin-react";
  3. import path from "path";
  4. // https://vite.dev/config/
  5. export default defineConfig({
  6. plugins: [react()],
  7. css: {
  8. modules: {
  9. generateScopedName: "[name]__[local]___[hash:base64:5]", // 自定义类名生成规则
  10. },
  11. },
  12. resolve: {
  13. alias: {
  14. "@": path.resolve(__dirname, "src"),
  15. },
  16. // mainFields: ['module', 'jsnext:main', 'jsnext', 'main'],
  17. },
  18. server: {
  19. host: true,
  20. port: 8080,
  21. open: true,
  22. cors: true,
  23. // vite 反向代理
  24. proxy: {
  25. "/api": {
  26. target: "http://192.168.1.112:19801",
  27. changeOrigin: false,
  28. rewrite: (path) => path.replace(/^\/api/, ""),
  29. },
  30. },
  31. },
  32. build: {
  33. // 静态资源打包到dist下的不同目录
  34. rollupOptions: {
  35. output: {
  36. chunkFileNames: 'static/js/[name]-[hash].js',
  37. entryFileNames: 'static/js/[name]-[hash].js',
  38. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  39. },
  40. }
  41. }
  42. });