Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

vite.config.ts 3.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  1. import { sveltekit } from "@sveltejs/kit/vite";
  2. import Icons from "unplugin-icons/vite";
  3. import { promises } from "fs";
  4. import { defineConfig } from "vitest/config";
  5. import { resolve } from "path";
  6. import fs from "fs-extra";
  7. import { spawn } from "child_process";
  8. import type { Plugin } from "vite";
  9. // used to load fonts server side for thumbnail generation
  10. function loadTTFAsArrayBuffer() {
  11. return {
  12. name: "load-ttf-as-array-buffer",
  13. async transform(_src, id) {
  14. if (id.endsWith(".ttf")) {
  15. return `export default new Uint8Array([
  16. ${new Uint8Array(await promises.readFile(id))}
  17. ]).buffer`;
  18. }
  19. },
  20. };
  21. }
  22. const isViteNode = process.argv.some((arg) => arg.includes("vite-node")) || !!process.env.VITE_NODE;
  23. const skipLlamaCppBuild = process.env.SKIP_LLAMA_CPP_BUILD === "true";
  24. const shouldCopyLlama =
  25. process.env.npm_lifecycle_event === "build" && !isViteNode && !skipLlamaCppBuild; // Copy node-llama-cpp/llama files to build output
  26. function copyLlamaFiles() {
  27. return {
  28. name: "copy-llama-files",
  29. apply: "build" as const,
  30. closeBundle: async () => {
  31. try {
  32. // Run npx command first and pipe IO
  33. console.log("Running node-llama-cpp source download...");
  34. await new Promise((resolve, reject) => {
  35. const npxProcess = spawn("npx", ["--no", "node-llama-cpp", "source", "download"], {
  36. stdio: "inherit", // Pipe all IO to parent process
  37. shell: true,
  38. });
  39. npxProcess.on("close", (code) => {
  40. if (code === 0) {
  41. console.log("✓ Successfully downloaded llama source files");
  42. resolve(code);
  43. } else {
  44. reject(new Error(`npx command failed with code ${code}`));
  45. }
  46. });
  47. npxProcess.on("error", (err) => {
  48. reject(err);
  49. });
  50. });
  51. const sourcePath = resolve("node_modules/node-llama-cpp/llama");
  52. const destPath = resolve("build/server/llama");
  53. // Ensure destination directory exists
  54. await fs.ensureDir(destPath);
  55. // Copy files - using a filter to prevent copying files to subdirectories of themselves
  56. await fs.copy(sourcePath, destPath, {
  57. filter: (src, dest) => {
  58. // Skip if source path is inside destination path or vice versa
  59. if (src.includes(destPath) || dest.includes(sourcePath)) {
  60. console.log(`Skipping problematic copy: ${src} -> ${dest}`);
  61. return false;
  62. }
  63. return true;
  64. },
  65. overwrite: true,
  66. dereference: true,
  67. });
  68. console.log("✓ Successfully copied llama files to build output");
  69. } catch (error) {
  70. console.error("Error in llama files process:", error);
  71. }
  72. },
  73. } satisfies Plugin;
  74. }
  75. export default defineConfig({
  76. plugins: [
  77. sveltekit(),
  78. Icons({
  79. compiler: "svelte",
  80. }),
  81. loadTTFAsArrayBuffer(),
  82. ...(shouldCopyLlama ? [copyLlamaFiles()] : []),
  83. ],
  84. optimizeDeps: {
  85. include: ["uuid", "@huggingface/transformers", "sharp", "@gradio/client", "clsx"],
  86. },
  87. test: {
  88. workspace: [
  89. {
  90. // Client-side tests (Svelte components)
  91. extends: "./vite.config.ts",
  92. test: {
  93. name: "client",
  94. environment: "browser",
  95. browser: {
  96. enabled: true,
  97. provider: "playwright",
  98. instances: [{ browser: "chromium", headless: true }],
  99. },
  100. include: ["src/**/*.svelte.{test,spec}.{js,ts}"],
  101. exclude: ["src/lib/server/**", "src/**/*.ssr.{test,spec}.{js,ts}"],
  102. setupFiles: ["./scripts/setups/vitest-setup-client.ts"],
  103. },
  104. },
  105. {
  106. // SSR tests (Server-side rendering)
  107. extends: "./vite.config.ts",
  108. test: {
  109. name: "ssr",
  110. environment: "node",
  111. include: ["src/**/*.ssr.{test,spec}.{js,ts}"],
  112. },
  113. },
  114. {
  115. // Server-side tests (Node.js utilities)
  116. extends: "./vite.config.ts",
  117. test: {
  118. name: "server",
  119. environment: "node",
  120. include: ["src/**/*.{test,spec}.{js,ts}"],
  121. exclude: ["src/**/*.svelte.{test,spec}.{js,ts}", "src/**/*.ssr.{test,spec}.{js,ts}"],
  122. setupFiles: ["./scripts/setups/vitest-setup-server.ts"],
  123. },
  124. },
  125. ],
  126. },
  127. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...