-
Notifications
You must be signed in to change notification settings - Fork 837
/
vite.config.shared.ts
63 lines (61 loc) · 1.65 KB
/
vite.config.shared.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
import type { Plugin, UserConfig } from 'vite';
import * as path from 'node:path';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import { nodeExternals } from 'rollup-plugin-node-externals';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import dts from 'vite-plugin-dts';
export interface Options {
root: string;
types?: boolean;
nodeExternals?: boolean;
excludeMonoRepoPackages?: boolean;
}
export function createShareConfig(options: Options): UserConfig {
const plugins: Plugin[] = [
nodeResolve({
browser: false,
preferBuiltins: true,
}),
cleanup({
comments: 'none',
extensions: ['js', 'ts'],
}),
checker({
typescript: true,
}),
];
if (options.types) {
plugins.push(
dts({
rollupTypes: true,
}),
);
}
if (options.nodeExternals) {
const exclude = new Array<RegExp>();
if (options.excludeMonoRepoPackages) {
exclude.push(/^@chatgpt-telegram-workers\/.+/);
}
plugins.push(
nodeExternals({
exclude,
}),
);
}
return defineConfig({
plugins,
build: {
target: 'esnext',
lib: {
entry: path.resolve(options.root, 'src/index'),
fileName: 'index',
formats: ['es'],
},
sourcemap: true,
minify: false,
outDir: path.resolve(options.root, 'dist'),
},
});
}