-
Notifications
You must be signed in to change notification settings - Fork 69
/
vite.config.ts
84 lines (81 loc) · 2.18 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
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import { AntdvLessPlugin, AntdvModifyVars } from 'stepin/lib/style/plugins';
const timestamp = new Date().getTime();
const prodRollupOptions = {
output: {
chunkFileNames: (chunk) => {
return 'assets/' + chunk.name + '.[hash]' + '.' + timestamp + '.js';
},
assetFileNames: (asset) => {
const name = asset.name;
if (name && (name.endsWith('.css') || name.endsWith('.js'))) {
const names = name.split('.');
const extname = names.splice(names.length - 1, 1)[0];
return `assets/${names.join('.')}.[hash].${timestamp}.${extname}`;
}
return 'assets/' + asset.name;
},
},
};
// vite 配置
export default ({ command, mode }) => {
// 获取环境变量
const env = loadEnv(mode, process.cwd());
console.log(mode);
return defineConfig({
server: {
proxy: {
'/api': {
target: env.VITE_API_URL,
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
hmr: true,
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
build: {
sourcemap: true,
chunkSizeWarningLimit: 2048,
rollupOptions: mode === 'production' ? prodRollupOptions : {},
},
plugins: [
vue({
template: {
transformAssetUrls: {
img: ['src'],
'a-avatar': ['src'],
'stepin-view': ['logo-src', 'presetThemeList'],
'a-card': ['cover'],
},
},
}),
Components({
resolvers: [AntDesignVueResolver({ importStyle: mode === 'development' ? false : 'less' })],
}),
],
css: {
preprocessorOptions: {
less: {
plugins: [AntdvLessPlugin],
modifyVars: AntdvModifyVars,
javascriptEnabled: true,
},
},
},
base: env.VITE_BASE_URL,
});
};