vite.config.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. watch: {
  28. // usePolling: true
  29. },
  30. },
  31. plugins: [
  32. react(),
  33. svgr({
  34. svgrOptions: {
  35. // icon: true,
  36. // typescript: true,
  37. },
  38. }),
  39. ],
  40. css: {
  41. preprocessorOptions: {
  42. scss: {
  43. api: "modern",
  44. },
  45. },
  46. modules: {
  47. // hashPrefix: 'hash',
  48. // generateScopedName: "[name]__[local]__[hash:base64:2]",
  49. // globalModulePaths: [
  50. // /.*\\.global\\..*/
  51. // ]
  52. },
  53. postcss: {
  54. plugins: [],
  55. },
  56. },
  57. }
  58. })