-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
161 lines (156 loc) · 4.03 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* @Description: vite配置
* @Author: Gavin
* @Date: 2021-05-01 00:48:47
* @LastEditTime: 2023-02-04 13:54:20
* @LastEditors: GAtomis
*/
import { UserConfig, ConfigEnv, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// import eruda from 'vite-plugin-eruda'//调试工具
// import viteImagemin from 'vite-plugin-imagemin' //图片压缩
import viteCompression from 'vite-plugin-compression' //包压缩支持Gzip
import { viteMockServe } from 'vite-plugin-mock' //mock
//cdn
// import importToCDN, { autoComplete } from 'vite-plugin-cdn-import'
import vueJsx from '@vitejs/plugin-vue-jsx' //jsx插件
import themePreprocessorPlugin from '@zougt/vite-plugin-theme-preprocessor'
// Pre-Bundling optimization 3q anfu
import OptimizationPersist from 'vite-plugin-optimize-persist'
//
import PkgConfig from 'vite-plugin-package-config'
import svgLoader from 'vite-svg-loader'
// import compress from 'vite-plugin-compress'
// function pathResolve(dir: string) {
// return resolve(process.cwd(), '.', dir);
// }
// https://vitejs.dev/config/
const setTheme = () =>
themePreprocessorPlugin({
less: {
// // 启用任意主题色模式
arbitraryMode: false,
// // 默认的主题色,用于对其他颜色值形成对比值,通常与 src/theme/theme-vars.less 中的一个主题色相同,也可以不相同,就看是不是你想要的效果
// defaultPrimaryColor: "#18ffb2",
// 各个主题文件的位置
multipleScopeVars: [
{
scopeName: 'theme-default',
path: resolve('src/themes/default.less'),
},
{
scopeName: 'theme-dark',
path: resolve('src/themes/dark.less'),
},
],
// css中不是由主题色变量生成的颜色,也让它抽取到主题css内,可以提高权重
includeStyleWithColors: [
{
color: '#ffffff',
},
],
defaultScopeName: 'theme-default',
extract: false,
},
})
//在暂时废弃
// const imagemin = () => {
// return viteImagemin({
// gifsicle: {
// optimizationLevel: 7,
// interlaced: false,
// },
// optipng: {
// optimizationLevel: 7,
// },
// mozjpeg: {
// quality: 20,
// },
// pngquant: {
// quality: [0.8, 0.9],
// speed: 4,
// },
// svgo: {
// plugins: [
// {
// name: 'removeViewBox',
// },
// {
// name: 'removeEmptyAttrs',
// active: false,
// },
// ],
// },
// })
// }
//set CDN
// function configCDN() {
// return importToCDN({
// modules: [
// {
// name: 'three',
// var: 'three',
// path: 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js',
// },
// ],
// })
// }
export default ({ command, mode }: ConfigEnv): UserConfig => {
const env = loadEnv(mode, __dirname)
return {
base: './', //绝对路径配置根据ngxin
resolve: {
alias: [
{
find: '@',
replacement: resolve(__dirname, './src'),
},
],
},
server: {
host: '0.0.0.0',
open: true,
port: +env.VITE_PORT,
// https: true,
proxy: {
'/api': {
target: env.VITE_PROXY_URL,
changeOrigin: true,
},
'/upload':{
target: 'https://smms.app',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/upload/, '')
},
},
},
css: {
preprocessorOptions: {
less: {
modifyVars: {},
javascriptEnabled: true,
},
scss: {
additionalData: `
@use 'sass:math';
@import "src/styles/global.scss";
`,
},
},
},
plugins: [
vue(),
vueJsx(),
,
viteCompression({ deleteOriginFile: !true }),
// imagemin(),
svgLoader(),
viteMockServe({ supportTs: true }),
setTheme(),
// configCDN(),
PkgConfig(),
OptimizationPersist(),
],
}
}