forked from TBXark/ChatGPT-Telegram-Workers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
72 lines (69 loc) · 1.81 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
62
63
64
65
66
67
68
69
70
71
72
import * as path from 'node:path';
import type { LibraryFormats, Plugin } from 'vite';
import { defineConfig } from 'vite';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import checker from 'vite-plugin-checker';
import nodeExternals from 'rollup-plugin-node-externals';
import dts from 'vite-plugin-dts';
import { createVersionPlugin, versionDefine } from './scripts/plugins/version';
import { createDockerPlugin } from './scripts/plugins/docker';
const { BUILD_MODE } = process.env;
const plugins: Plugin[] = [
nodeResolve({
preferBuiltins: true,
}),
cleanup({
comments: 'none',
extensions: ['js', 'ts'],
}),
checker({
typescript: true,
}),
nodeExternals(),
];
let entry: string;
let outDir = 'dist';
let fileName = 'index';
let formats: LibraryFormats[] = ['es'];
switch (BUILD_MODE) {
case 'plugins-page':
entry = 'src/plugins/interpolate.ts';
fileName = 'interpolate';
outDir = 'plugins/dist';
break;
case 'local':
entry = 'src/adapter/local/index.ts';
plugins.push(createDockerPlugin('dist'));
break;
case 'vercel':
entry = 'src/adapter/vercel/index.ts';
break;
case 'pack':
entry = 'src/index.ts';
formats = ['es', 'cjs'];
plugins.push(dts({
rollupTypes: true,
}));
break;
default:
entry = 'src/index.ts';
plugins.push(createVersionPlugin('dist'));
break;
}
export default defineConfig({
plugins,
build: {
target: 'esnext',
lib: {
entry: path.resolve(__dirname, entry),
fileName,
formats,
},
minify: false,
outDir,
},
define: {
...versionDefine,
},
});