vite.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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(__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(__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("react") || id.includes("scheduler")) {
  36. return "react-vendor"
  37. }
  38. if (id.includes("@milkdown")) {
  39. return "milkdown-vendor"
  40. }
  41. if (id.includes("katex") || id.includes("remark-math") || id.includes("rehype-katex")) {
  42. return "katex-vendor"
  43. }
  44. if (id.includes("cytoscape")) {
  45. return "cytoscape-vendor"
  46. }
  47. if (id.includes("@react-sigma") || id.includes("sigma")) {
  48. return "sigma-vendor"
  49. }
  50. if (id.includes("graphology")) {
  51. return "graphology-vendor"
  52. }
  53. }
  54. // Split large book-analysis modules into their own chunk
  55. if (id.includes("/src/lib/novel/book-analysis/")) {
  56. return "book-analysis-vendor"
  57. }
  58. return undefined
  59. },
  60. },
  61. },
  62. },
  63. // 2. tauri expects a fixed port, fail if that port is not available
  64. server: {
  65. port: 1420,
  66. strictPort: true,
  67. host: host || false,
  68. hmr: host
  69. ? {
  70. protocol: "ws",
  71. host,
  72. port: 1421,
  73. }
  74. : undefined,
  75. watch: {
  76. ignored: [
  77. "**/src-tauri/**",
  78. "**/node_modules/**",
  79. "**/dist/**",
  80. "**/.vite/**",
  81. "**/.novel/**",
  82. "**/chapters/**",
  83. "**/wiki/**",
  84. "**/target/**",
  85. "**/*.snapshot.*",
  86. "**/*.json",
  87. "**/*.store",
  88. ],
  89. },
  90. },
  91. test: {
  92. environment: "node",
  93. // Loads .env.test.local into process.env for real-LLM tests.
  94. // The loader itself is a no-op if the file is absent, so this is
  95. // safe to keep on for every test run.
  96. setupFiles: ["./src/test-helpers/load-test-env.ts"],
  97. exclude: [
  98. "**/node_modules/**",
  99. "**/dist/**",
  100. "**/cypress/**",
  101. "**/.{idea,git,cache,output,temp}/**",
  102. "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
  103. "**/.worktrees/**",
  104. ],
  105. },
  106. }))