vite.config.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { defineConfig } from "vite"
  2. import react from "@vitejs/plugin-react"
  3. import svgr from "vite-plugin-svgr"
  4. import { name } from "./package.json"
  5. const genBaseUrl = (mode) => {
  6. if (mode !== "development") {
  7. if (mode == "test") {
  8. return `/${name}-test/`
  9. }
  10. return `/${name}/`
  11. }
  12. return "/"
  13. }
  14. export default defineConfig(({ mode }) => {
  15. return {
  16. resolve: {
  17. alias: {
  18. "@": "/src",
  19. },
  20. },
  21. base: genBaseUrl(mode),
  22. build: {
  23. // cssCodeSplit: false,
  24. // target: "es2015",
  25. },
  26. server: {
  27. host: "0.0.0.0",
  28. allowedHosts: true,
  29. port: 8080,
  30. watch: {
  31. // usePolling: true
  32. },
  33. },
  34. plugins: [
  35. react(),
  36. svgr({
  37. svgrOptions: {
  38. // icon: true,
  39. // typescript: true,
  40. },
  41. }),
  42. ],
  43. css: {
  44. preprocessorOptions: {
  45. scss: {
  46. api: "modern",
  47. },
  48. },
  49. modules: {
  50. // hashPrefix: 'hash',
  51. // generateScopedName: "[name]__[local]__[hash:base64:2]",
  52. // globalModulePaths: [
  53. // /.*\\.global\\..*/
  54. // ]
  55. },
  56. postcss: {
  57. plugins: [],
  58. },
  59. },
  60. }
  61. })