-
Notifications
You must be signed in to change notification settings - Fork 129
/
vite.config.ts
85 lines (76 loc) · 2.33 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
import {defineConfig,loadEnv} from 'vite';
import react from '@vitejs/plugin-react-swc';
import {viteSingleFile} from 'vite-plugin-singlefile';
import svgx from '@svgx/vite-plugin-react';
import {obfuscator} from 'rollup-obfuscator';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite'
import UnoCSS from 'unocss/vite'
import vitePluginString from 'vite-plugin-string'
const isDev = process.env.NODE_ENV === 'development';
const ifCompress = (fn: () => any, defaultVal: any = {}) => {
if (!isDev)
return fn();
return defaultVal;
};
export const commonConfig = () => {
return {
resolve: {
alias: {
'@/': `${ path.resolve(__dirname, 'src') }/`,
},
},
};
};
export default ({mode})=>{
Object.assign(process.env, loadEnv(mode, process.cwd()))
const hostUrl = process.env.VITE_MIDJOURNEY_PROXY_URL;
return defineConfig({
...commonConfig(),
server: {
proxy: {
'/mj-api': {
target:hostUrl,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/mj-api/, ''),
},
},
},
plugins: [
vitePluginString(),
UnoCSS(),
react(),
svgx(),
AutoImport({
imports: ['react','react-router-dom'],
dts: "./auto-imports.d.ts",
}),
viteSingleFile(),
ifCompress(() => obfuscator({
optionsPreset: 'low-obfuscation',
}))
],
esbuild: {
drop: ['debugger'],
pure: ifCompress(() => {
return ['console.log', 'console.error', 'console.warn', 'console.debug', 'console.trace']
}, []),
},
build: {
outDir: `dist`,
minify: ifCompress(() => 'esbuild', false),
sourcemap: isDev,
watch: isDev ? {} : null,
cssCodeSplit: false,
assetsInlineLimit: 100000000000000000,
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
},
output: {
entryFileNames: 'assets/[name].js',
},
},
},
});
}