|
1 | | -// IMPORTANT NOTE: This file is only used in two situations: local development, and the live preview in Workbench. |
2 | | -// For deployed Sparks, the `server/main.ts` serves the app itself. Ensure consistency between this file and `server/main.ts` |
3 | | -// if you have something that needs to available while deployed. |
4 | | - |
5 | 1 | import tailwindcss from "@tailwindcss/vite"; |
6 | 2 | import react from "@vitejs/plugin-react-swc"; |
7 | 3 | import { defineConfig, PluginOption } from "vite"; |
8 | 4 |
|
9 | | -import { createLogToFileLogger } from "@github/spark/logToFileLogger"; |
10 | | -import { runtimeTelemetryPlugin } from "@github/spark/telemetryPlugin"; |
11 | | -import sparkAgent from "@github/spark/agent-plugin"; |
12 | | -import { tagSourcePlugin, designerHost } from "@github/spark/designerPlugin"; |
| 5 | +import sparkPlugin from "@github/spark/spark-vite-plugin"; |
13 | 6 | import createIconImportProxy from "@github/spark/vitePhosphorIconProxyPlugin"; |
14 | 7 | import { resolve } from 'path' |
15 | 8 |
|
16 | | -const GITHUB_RUNTIME_PERMANENT_NAME = process.env.GITHUB_RUNTIME_PERMANENT_NAME |
17 | | -const GITHUB_API_URL = process.env.GITHUB_API_URL || "https://api.github.com"; |
18 | 9 | const projectRoot = process.env.PROJECT_ROOT || import.meta.dirname |
19 | 10 |
|
20 | | -const addGitHubAuth = (proxy, options) => { |
21 | | - proxy.on('proxyReq', (proxyReq, req, res) => { |
22 | | - if (process.env.GITHUB_TOKEN) { |
23 | | - proxyReq.setHeader('Authorization', `bearer ${process.env.GITHUB_TOKEN}`); |
24 | | - } |
25 | | - }); |
26 | | -}; |
27 | | - |
28 | 11 | // https://vite.dev/config/ |
29 | 12 | export default defineConfig({ |
30 | 13 | plugins: [ |
31 | | - createIconImportProxy(), |
32 | 14 | react(), |
33 | 15 | tailwindcss(), |
34 | | - runtimeTelemetryPlugin(), |
35 | | - sparkAgent({ serverURL: process.env.SPARK_AGENT_URL }) as PluginOption, |
36 | | - tagSourcePlugin() as PluginOption, |
37 | | - designerHost() as PluginOption, |
| 16 | + // DO NOT REMOVE |
| 17 | + createIconImportProxy() as PluginOption, |
| 18 | + sparkPlugin() as PluginOption, |
38 | 19 | ], |
39 | | - build: { |
40 | | - outDir: process.env.OUTPUT_DIR || 'dist' |
41 | | - }, |
42 | | - define: { |
43 | | - // ensure that you give these types in `src/vite-end.d.ts` |
44 | | - GITHUB_RUNTIME_PERMANENT_NAME: JSON.stringify(GITHUB_RUNTIME_PERMANENT_NAME), |
45 | | - BASE_KV_SERVICE_URL: JSON.stringify("/_spark/kv"), |
46 | | - }, |
47 | | - server: { |
48 | | - port: 5000, |
49 | | - hmr: { |
50 | | - overlay: false, |
51 | | - }, |
52 | | - cors: { |
53 | | - origin: /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\]|(?:.*\.)?github\.com)(?::\d+)?$/ |
54 | | - }, |
55 | | - watch: { |
56 | | - ignored: [ |
57 | | - "**/prd.md", |
58 | | - "**.log", |
59 | | - "**/.azcopy/**", |
60 | | - ], |
61 | | - awaitWriteFinish: { |
62 | | - pollInterval: 50, |
63 | | - stabilityThreshold: 100, |
64 | | - }, |
65 | | - }, |
66 | | - warmup: { |
67 | | - clientFiles: [ |
68 | | - "./src/App.tsx", |
69 | | - "./src/index.css", |
70 | | - "./index.html", |
71 | | - "./src/**/*.tsx", |
72 | | - "./src/**/*.ts", |
73 | | - "./src/**/*.jsx", |
74 | | - "./src/**/*.js", |
75 | | - "./src/styles/theme.css", |
76 | | - ], |
77 | | - }, |
78 | | - proxy: { |
79 | | - "^/_spark/llm": { |
80 | | - target: "https://models.github.ai/inference/chat/completions", |
81 | | - changeOrigin: true, |
82 | | - ignorePath: true, |
83 | | - configure: addGitHubAuth |
84 | | - }, |
85 | | - "^/_spark/.*": { |
86 | | - target: GITHUB_API_URL, |
87 | | - changeOrigin: true, |
88 | | - rewrite: (path) => { |
89 | | - const serviceName = path.replace("/_spark/", "").split("/")[0]; |
90 | | - return path.replace(`/_spark/${serviceName}`, `/runtime/${GITHUB_RUNTIME_PERMANENT_NAME}/${serviceName}`); |
91 | | - }, |
92 | | - configure: addGitHubAuth |
93 | | - } |
94 | | - }, |
95 | | - }, |
96 | 20 | resolve: { |
97 | 21 | alias: { |
98 | 22 | '@': resolve(projectRoot, 'src') |
99 | 23 | } |
100 | 24 | }, |
101 | | - customLogger: createLogToFileLogger(), |
102 | 25 | }); |
0 commit comments