vite.config.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import path from "path"
  2. import { readFileSync } from "fs"
  3. import { defineConfig } from "vite"
  4. import react from "@vitejs/plugin-react"
  5. import tailwindcss from "@tailwindcss/vite"
  6. const host = process.env.TAURI_DEV_HOST
  7. // Read version from package.json at config-load time so the Settings
  8. // UI can show the running app version without duplicating the string.
  9. const pkgJson = JSON.parse(readFileSync(path.resolve(import.meta.dirname, "package.json"), "utf-8"))
  10. // https://vitejs.dev/config/
  11. export default defineConfig(async () => ({
  12. plugins: [react(), tailwindcss()],
  13. resolve: {
  14. alias: { "@": path.resolve(import.meta.dirname, "./src") },
  15. },
  16. define: {
  17. __APP_VERSION__: JSON.stringify(pkgJson.version),
  18. __BUILD_TIME__: JSON.stringify(new Date().toISOString()),
  19. },
  20. // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  21. //
  22. // 1. prevent vite from obscuring rust errors
  23. clearScreen: false,
  24. build: {
  25. chunkSizeWarningLimit: 700,
  26. modulePreload: {
  27. resolveDependencies(_filename: string, deps: string[]) {
  28. return deps.filter((dep) => !dep.includes("graphology-vendor"))
  29. },
  30. },
  31. rollupOptions: {
  32. output: {
  33. manualChunks(id: string) {
  34. if (id.includes("node_modules")) {
  35. if (id.includes("opencc-js")) {
  36. return "opencc-vendor"
  37. }
  38. if (id.includes("pinyin-pro")) {
  39. return "pinyin-vendor"
  40. }
  41. if (id.includes("js-yaml")) {
  42. return "yaml-vendor"
  43. }
  44. if (id.includes("@react-sigma") || id.includes("sigma")) {
  45. return "sigma-vendor"
  46. }
  47. if (id.includes("graphology")) {
  48. return "graphology-vendor"
  49. }
  50. if (id.includes("react") || id.includes("scheduler")) {
  51. return "react-vendor"
  52. }
  53. if (id.includes("@milkdown")) {
  54. return "milkdown-vendor"
  55. }
  56. if (id.includes("katex") || id.includes("remark-math") || id.includes("rehype-katex")) {
  57. return "katex-vendor"
  58. }
  59. if (id.includes("cytoscape")) {
  60. return "cytoscape-vendor"
  61. }
  62. }
  63. return undefined
  64. },
  65. },
  66. },
  67. },
  68. // 2. tauri expects a fixed port, fail if that port is not available
  69. server: {
  70. port: 1420,
  71. strictPort: true,
  72. host: host || false,
  73. hmr: host
  74. ? {
  75. protocol: "ws",
  76. host,
  77. port: 1421,
  78. }
  79. : undefined,
  80. watch: {
  81. ignored: [
  82. "**/src-tauri/**",
  83. "**/node_modules/**",
  84. "**/dist/**",
  85. "**/.vite/**",
  86. "**/.novel/**",
  87. "**/chapters/**",
  88. "**/wiki/**",
  89. "**/target/**",
  90. "**/*.snapshot.*",
  91. "**/*.json",
  92. "**/*.store",
  93. ],
  94. },
  95. },
  96. test: {
  97. environment: "node",
  98. // Loads .env.test.local into process.env for real-LLM tests.
  99. // The loader itself is a no-op if the file is absent, so this is
  100. // safe to keep on for every test run.
  101. setupFiles: ["./src/test-helpers/load-test-env.ts"],
  102. exclude: [
  103. "**/node_modules/**",
  104. "**/dist/**",
  105. "**/cypress/**",
  106. "**/.{idea,git,cache,output,temp}/**",
  107. "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
  108. "**/.worktrees/**",
  109. ],
  110. },
  111. }))