-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
61 lines (55 loc) · 1.61 KB
/
vite.config.js
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 { defineConfig, loadEnv } from 'vite';
import { wrapperEnv } from './build/utils';
import { createRollupPlugins } from './build/rollup/plugin';
import { createVitePlugins } from './build/vite/plugin';
import visualizer from 'rollup-plugin-visualizer';
import { resolve } from 'path';
function pathResolve(dir) {
return resolve(process.cwd(), '.', dir);
}
export default defineConfig(({ command, mode }) => {
const root = process.cwd();
const env = loadEnv(mode, root);
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
const viteEnv = wrapperEnv(env);
const {
VITE_PUBLIC_PATH,
VITE_DROP_CONSOLE,
VITE_DROP_DEBUGGER,
VITE_KEEP_INFINITY
} = viteEnv;
return {
base: VITE_PUBLIC_PATH,
root,
resolve: {
// import as /@/xxx, it cannot start with @ because that's considered a package. link: https://github.com/vitejs/vite/issues/279
alias: [{
find: /\/@\//,
replacement: pathResolve('src') + '/',
}],
},
build: {
target: 'es2015',
outDir: 'dist',
terserOptions: {
compress: {
keep_infinity: VITE_KEEP_INFINITY,
// Used to delete console in production environment
drop_console: VITE_DROP_CONSOLE,
drop_debugger: VITE_DROP_DEBUGGER
},
},
rollupOptions: {
plugins: createRollupPlugins(viteEnv, mode),
output: {
manualChunks: {
// todo: ...
}
}
},
sourcemap: true,
chunkSizeWarningLimit: 500,
},
plugins: createVitePlugins(viteEnv, mode)
}
})