legends810 commited on
Commit
deea547
·
verified ·
1 Parent(s): bee84ba

Upload vite.config.ts with huggingface_hub

Browse files
Files changed (1) hide show
  1. vite.config.ts +155 -0
vite.config.ts ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { cloudflareDevProxyVitePlugin as remixCloudflareDevProxy, vitePlugin as remixVitePlugin } from '@remix-run/dev';
2
+ import UnoCSS from 'unocss/vite';
3
+ import { defineConfig, type ViteDevServer } from 'vite';
4
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
5
+ import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
6
+ import tsconfigPaths from 'vite-tsconfig-paths';
7
+ import * as dotenv from 'dotenv';
8
+ import { execSync } from 'child_process';
9
+ import { readFileSync } from 'fs';
10
+ import { join } from 'path';
11
+
12
+ dotenv.config();
13
+
14
+ // Get detailed git info with fallbacks
15
+ const getGitInfo = () => {
16
+ try {
17
+ return {
18
+ commitHash: execSync('git rev-parse --short HEAD').toString().trim(),
19
+ branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
20
+ commitTime: execSync('git log -1 --format=%cd').toString().trim(),
21
+ author: execSync('git log -1 --format=%an').toString().trim(),
22
+ email: execSync('git log -1 --format=%ae').toString().trim(),
23
+ remoteUrl: execSync('git config --get remote.origin.url').toString().trim(),
24
+ repoName: execSync('git config --get remote.origin.url')
25
+ .toString()
26
+ .trim()
27
+ .replace(/^.*github.com[:/]/, '')
28
+ .replace(/\.git$/, ''),
29
+ };
30
+ } catch {
31
+ return {
32
+ commitHash: 'no-git-info',
33
+ branch: 'unknown',
34
+ commitTime: 'unknown',
35
+ author: 'unknown',
36
+ email: 'unknown',
37
+ remoteUrl: 'unknown',
38
+ repoName: 'unknown',
39
+ };
40
+ }
41
+ };
42
+
43
+ // Read package.json with detailed dependency info
44
+ const getPackageJson = () => {
45
+ try {
46
+ const pkgPath = join(process.cwd(), 'package.json');
47
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
48
+
49
+ return {
50
+ name: pkg.name,
51
+ description: pkg.description,
52
+ license: pkg.license,
53
+ dependencies: pkg.dependencies || {},
54
+ devDependencies: pkg.devDependencies || {},
55
+ peerDependencies: pkg.peerDependencies || {},
56
+ optionalDependencies: pkg.optionalDependencies || {},
57
+ };
58
+ } catch {
59
+ return {
60
+ name: 'bolt.diy',
61
+ description: 'A DIY LLM interface',
62
+ license: 'MIT',
63
+ dependencies: {},
64
+ devDependencies: {},
65
+ peerDependencies: {},
66
+ optionalDependencies: {},
67
+ };
68
+ }
69
+ };
70
+
71
+ const pkg = getPackageJson();
72
+ const gitInfo = getGitInfo();
73
+
74
+ export default defineConfig((config) => {
75
+ return {
76
+ define: {
77
+ __COMMIT_HASH: JSON.stringify(gitInfo.commitHash),
78
+ __GIT_BRANCH: JSON.stringify(gitInfo.branch),
79
+ __GIT_COMMIT_TIME: JSON.stringify(gitInfo.commitTime),
80
+ __GIT_AUTHOR: JSON.stringify(gitInfo.author),
81
+ __GIT_EMAIL: JSON.stringify(gitInfo.email),
82
+ __GIT_REMOTE_URL: JSON.stringify(gitInfo.remoteUrl),
83
+ __GIT_REPO_NAME: JSON.stringify(gitInfo.repoName),
84
+ __APP_VERSION: JSON.stringify(process.env.npm_package_version),
85
+ __PKG_NAME: JSON.stringify(pkg.name),
86
+ __PKG_DESCRIPTION: JSON.stringify(pkg.description),
87
+ __PKG_LICENSE: JSON.stringify(pkg.license),
88
+ __PKG_DEPENDENCIES: JSON.stringify(pkg.dependencies),
89
+ __PKG_DEV_DEPENDENCIES: JSON.stringify(pkg.devDependencies),
90
+ __PKG_PEER_DEPENDENCIES: JSON.stringify(pkg.peerDependencies),
91
+ __PKG_OPTIONAL_DEPENDENCIES: JSON.stringify(pkg.optionalDependencies),
92
+ },
93
+ build: {
94
+ target: 'esnext',
95
+ },
96
+ plugins: [
97
+ nodePolyfills({
98
+ include: ['path', 'buffer', 'process'],
99
+ }),
100
+ config.mode !== 'test' && remixCloudflareDevProxy(),
101
+ remixVitePlugin({
102
+ future: {
103
+ v3_fetcherPersist: true,
104
+ v3_relativeSplatPath: true,
105
+ v3_throwAbortReason: true,
106
+ v3_lazyRouteDiscovery: true,
107
+ },
108
+ }),
109
+ UnoCSS(),
110
+ tsconfigPaths(),
111
+ chrome129IssuePlugin(),
112
+ config.mode === 'production' && optimizeCssModules({ apply: 'build' }),
113
+ ],
114
+ envPrefix: [
115
+ 'VITE_',
116
+ 'OPENAI_LIKE_API_BASE_URL',
117
+ 'OLLAMA_API_BASE_URL',
118
+ 'LMSTUDIO_API_BASE_URL',
119
+ 'TOGETHER_API_BASE_URL',
120
+ ],
121
+ css: {
122
+ preprocessorOptions: {
123
+ scss: {
124
+ api: 'modern-compiler',
125
+ },
126
+ },
127
+ },
128
+ };
129
+ });
130
+
131
+ function chrome129IssuePlugin() {
132
+ return {
133
+ name: 'chrome129IssuePlugin',
134
+ configureServer(server: ViteDevServer) {
135
+ server.middlewares.use((req, res, next) => {
136
+ const raw = req.headers['user-agent']?.match(/Chrom(e|ium)\/([0-9]+)\./);
137
+
138
+ if (raw) {
139
+ const version = parseInt(raw[2], 10);
140
+
141
+ if (version === 129) {
142
+ res.setHeader('content-type', 'text/html');
143
+ res.end(
144
+ '<body><h1>Please use Chrome Canary for testing.</h1><p>Chrome 129 has an issue with JavaScript modules & Vite local development, see <a href="https://github.com/stackblitz/bolt.new/issues/86#issuecomment-2395519258">for more information.</a></p><p><b>Note:</b> This only impacts <u>local development</u>. `pnpm run build` and `pnpm run start` will work fine in this browser.</p></body>',
145
+ );
146
+
147
+ return;
148
+ }
149
+ }
150
+
151
+ next();
152
+ });
153
+ },
154
+ };
155
+ }