-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
81 lines (78 loc) · 2.05 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import viteCompression from 'vite-plugin-compression'
import legacyPlugin from '@vitejs/plugin-legacy'
import Components from 'unplugin-vue-components/vite'//按需引入Elements 页面不需要引入可以直接使用
import AutoImport from 'unplugin-auto-import/vite'
import {
ElementPlusResolver
} from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'
const pathResolve = (dir: string): any => {
return resolve(__dirname, ".", dir)
}
const alias: Record<string, string> = {
'@': pathResolve("src")
}
export default defineConfig({
//base: '',项目部署基础目录
plugins: [vue({
template: {
compilerOptions: {
isCustomElement: tag => tag === 'model-viewer'
}
}
}),viteCompression({
verbose: true,//gzip压缩
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz',
}),legacyPlugin({
targets: ['chrome 52'], // 需要兼容的目标列表,可以设置多个
additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件
}),
AutoImport({
imports:['vue', 'vue-router'],
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
build: {
minify: "terser",
terserOptions: {
//清除console和debugger
compress: {
drop_console: true,
drop_debugger: true,
},
},
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
manualChunks(id) { //静态资源分拆打包
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString();
}
}
}
}
},
resolve: {
alias
},
server: {
host: '0.0.0.0',
proxy: {
'/api': {
// target: 'http://47.108.172.21:5001/api/',
changeOrigin: true,
},
},
port: 3001
}
})