-
Notifications
You must be signed in to change notification settings - Fork 24
/
vite.config.ts
163 lines (153 loc) · 3.55 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import path, { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';
import type { RollupOptions } from 'rollup';
import type { BuildOptions, UserConfig } from 'vite';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const external = [
'react',
'os',
'fs',
'child_process',
'http',
'https',
'tty',
'process',
'path',
'net',
'stream',
'util',
'crypto',
'events',
'buffer',
'readline',
'node:os',
'node:fs',
'node:child_process',
'node:http',
'node:https',
'node:tty',
'node:process',
'node:path',
'node:net',
'node:stream',
'node:util',
'node:crypto',
'node:events',
'node:buffer',
'node:readline',
];
interface chunkOptimization {
assetsInlineLimit: number;
chunkSizeWarningLimit: number;
reportCompressedSize: boolean;
rollupOptions: RollupOptions;
minify: boolean | 'terser' | 'esbuild' | undefined;
}
const chunkOptimization: Partial<chunkOptimization> = {
chunkSizeWarningLimit: 500,
assetsInlineLimit: 1024,
reportCompressedSize: false,
rollupOptions: {
external,
output: {
experimentalMinChunkSize: 500,
},
treeshake: {
preset: 'recommended',
manualPureFunctions: ['console.log'],
},
},
minify: 'terser',
};
export const umd: BuildOptions = {
...chunkOptimization,
outDir: resolve(__dirname, 'dist/umd'),
lib: {
entry: resolve(__dirname, 'index.ts'),
name: 'ranuts',
fileName: 'index',
formats: ['umd'],
},
};
export const umdUtil: BuildOptions = {
...chunkOptimization,
outDir: resolve(__dirname, 'dist/umd/utils'),
lib: {
entry: resolve(__dirname, 'src/utils/index.ts'),
name: 'ranuts_utils',
fileName: 'utils',
formats: ['umd'],
},
};
export const umdWasm: BuildOptions = {
...chunkOptimization,
outDir: resolve(__dirname, 'dist/umd/wasm'),
lib: {
entry: resolve(__dirname, 'src/wasm/index.ts'),
name: 'ranuts_wasm',
fileName: 'wasm',
formats: ['umd'],
},
};
export const umdReact: BuildOptions = {
...chunkOptimization,
outDir: resolve(__dirname, 'dist/umd/react'),
lib: {
entry: resolve(__dirname, 'src/react/index.ts'),
name: 'ranuts_react',
fileName: 'react',
formats: ['umd'],
},
};
export const umdNode: BuildOptions = {
...chunkOptimization,
outDir: resolve(__dirname, 'dist/umd/node'),
lib: {
entry: resolve(__dirname, 'src/node/index.ts'),
name: 'ranuts_node',
fileName: 'node',
formats: ['umd'],
},
};
export const umdMl: BuildOptions = {
...chunkOptimization,
outDir: resolve(__dirname, 'dist/umd/ml'),
lib: {
entry: resolve(__dirname, 'src/ml/index.ts'),
name: 'ranuts_ml',
fileName: 'ml',
formats: ['umd'],
},
};
export const es: BuildOptions = {
...chunkOptimization,
lib: {
entry: {
react: resolve(__dirname, 'src/react/index.ts'),
utils: resolve(__dirname, 'src/utils/index.ts'),
wasm: resolve(__dirname, 'src/wasm/index.ts'),
node: resolve(__dirname, 'src/node/index.ts'),
ml: resolve(__dirname, 'src/ml/index.ts'),
index: resolve(__dirname, 'index.ts'),
},
fileName: (_: string, name: string): string => {
if (name === 'index') {
return `${name}.js`;
}
return `src/${name}/index.js`;
},
formats: ['es'],
},
};
export const viteConfig: UserConfig = {
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
},
plugins: [],
};
export default defineConfig(viteConfig);