-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvite.config.ts
61 lines (56 loc) · 1.67 KB
/
vite.config.ts
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
import { promises } from 'fs';
import { defineConfig, loadEnv } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';
import tsconfigPaths from 'vite-tsconfig-paths';
// used to load fonts server side for thumbnail generation
function loadTTFAsArrayBuffer() {
return {
name: 'load-ttf-as-array-buffer',
async transform(_src: any, id: any) {
if (id.endsWith('.ttf')) {
return `export default new Uint8Array([
${new Uint8Array(await promises.readFile(id))}
]).buffer`;
}
},
};
}
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '');
return {
build: {
target: 'esnext',
outDir: './dist',
sourcemap: true,
minify: false,
},
plugins: [
loadTTFAsArrayBuffer(),
tsconfigPaths(),
...VitePluginNode({
adapter: 'express',
appPath: './src/server.ts',
exportName: 'zods-llm-web-scrapper',
tsCompiler: 'esbuild',
}),
],
optimizeDeps: {
include: [
'browser-image-resizer',
'uuid',
'@huggingface/transformers',
'sharp',
'@gradio/client',
],
},
define: {
...Object.keys(env).reduce((prev, key) => {
const sanitizedKey = key.replace(/[^a-zA-Z0-9_]/g, '_');
prev[`process.env.${sanitizedKey}`] = JSON.stringify(env[key]);
return prev;
}, {}),
},
};
});