-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
107 lines (106 loc) · 2.99 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import fs from 'fs';
import removeConsole from 'vite-plugin-remove-console';
const optimizeDepsElementPlusIncludes = ['element-plus/es'];
fs.readdirSync('node_modules/element-plus/es/components').forEach((dirname) => {
fs.access(
`node_modules/element-plus/es/components/${dirname}/style/css.mjs`,
(err) => {
if (!err) {
optimizeDepsElementPlusIncludes.push(
`element-plus/es/components/${dirname}/style/css`
);
}
}
);
});
// https://vitejs.dev/config/
export default ({ mode, command }) => {
console.log(mode, command);
const boo = mode === 'dev';
console.log(boo);
const alias = {
'@': path.resolve(__dirname, './src'),
plugins: path.resolve(__dirname, './src/plugins'),
components: path.resolve(__dirname, './src/components')
};
return defineConfig({
base: './',
optimizeDeps: {
include: optimizeDepsElementPlusIncludes
},
plugins: [
vue(),
command === 'build' ? removeConsole() : '',
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
})
],
resolve: {
alias
},
css: {
devSourcemap: boo
},
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
host: '0.0.0.0',
port: 90,
open: true,
hmr: true,
strictPort: true
},
// to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ['VITE_', 'TAURI_'],
build: {
// Tauri supports es2021
target: ['es2021', 'chrome100', 'safari13'],
// don't minify for debug builds
minify: !boo ? 'esbuild' : false,
// produce sourcemaps for debug builds
/* terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}, */
sourcemap: boo,
assetsDir: 'static',
chunkSizeWarningLimit: 1500,
/* esbuild: {
drop: ['console', 'debugger']
}, */
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString();
}
},
chunkFileNames: (chunkInfo) => {
const facadeModuleId = chunkInfo.facadeModuleId
? chunkInfo.facadeModuleId.split('/')
: [];
const fileName =
facadeModuleId[facadeModuleId.length - 2] || '[name]';
return `js/${fileName}/[name].[hash].js`;
}
}
}
}
});
};