-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
106 lines (100 loc) · 2.48 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
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { visualizer } from 'rollup-plugin-visualizer';
import Components from 'unplugin-vue-components/vite';
import { config } from './config/postcss.config';
import {
ElementPlusResolver,
AntDesignVueResolver,
VantResolver,
HeadlessUiResolver,
ElementUiResolver,
} from 'unplugin-vue-components/resolvers';
type MyObject = {
[key: string]: string;
};
const loadEnv = (mode: string) => {
const env: [string] = require(`./env/.env.${mode}.js`);
const ret: MyObject = {};
for (const key in env) {
ret[key] = JSON.stringify(env[key]);
}
return ret;
};
export default defineConfig(async ({ command, mode, ssrBuild }) => {
const module = await import('internal-ip');
let host = await module.internalIpV4();
const base = JSON.parse(loadEnv(mode).BASE);
return {
base: base.trim(),
css: {
postcss: config,
devSourcemap: true,
preprocessorOptions: {
scss: {},
},
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
define: loadEnv(mode),
server: {
host: '0.0.0.0', // listen on all addresses
port: 5173,
strictPort: true,
hmr: {
protocol: 'ws',
host,
port: 5173,
},
},
build: {
chunkSizeWarningLimit: 10000, //lazy
rollupOptions: {
output: {
manualChunks: {
p5: ['p5'],
},
sanitizeFileName: (filename: string): string => {
if (filename.includes('plugin-vue')) {
return filename.replace('\0', '');
} else {
return filename;
}
},
},
},
},
plugins: [
vue(),
vueJsx(),
visualizer(),
Components({
// ui库解析器,也可以自定义
resolvers: [
ElementPlusResolver(),
AntDesignVueResolver(),
VantResolver(),
HeadlessUiResolver(),
ElementUiResolver(),
],
types: [
{
from: 'vue-codemirror',
names: ['Codemirror'],
},
],
dirs: ['src/components'],
// ui库解析器
// resolvers: [ElementPlusResolver()],
extensions: ['vue'],
// 配置文件生成位置
dts: 'src/components.d.ts',
}),
],
};
});