-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
138 lines (136 loc) · 5.28 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
import path from 'path';
import { defineConfig } from 'vite';
import type { ConfigEnv } from 'vite';
import Vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver, VueUseDirectiveResolver, VueUseComponentsResolver } from 'unplugin-vue-components/resolvers';
import AutoImport from 'unplugin-auto-import/vite';
import strip from '@rollup/plugin-strip';
import Unocss from 'unocss/vite';
import { presetAttributify, presetWind } from 'unocss';
import transformerDirective from '@unocss/transformer-directives';
import ImportIcons, { ImportIconsResolver } from 'vite-plugin-import-icons';
import zipPack from 'vite-plugin-zip-pack';
// 项目文件夹名
const folderName = path.basename(__dirname);
export default (env: ConfigEnv) => {
return defineConfig({
server: {
// https://cn.vitejs.dev/config/#server-proxy
proxy: {
'/mock': 'https://trsyapi.trscd.com.cn',
},
},
resolve: {
alias: {
'@/': `${path.resolve(__dirname, 'src')}/`,
},
},
base: './',
css: {
preprocessorOptions: {
less: {
additionalData: '@import "@/assets/styles/mixin.less";',
},
},
},
plugins: [
Vue(),
vueJsx(),
// 生产环境删除 debugger 和 console
env.mode === 'production' && strip({
include: ['**/*.js', '**/*.ts', '**/*.vue'],
}),
// https://github.com/antfu/unplugin-vue-components
Components({
dirs: ['src/components'],
deep: false,
extensions: ['vue', 'js', 'ts'],
include: [/\.vue$/, /\.vue\?vue/],
// 生成全局类型声明文件,以便 volar 类型提示
dts: 'src/types/components.d.ts',
resolvers: [
AntDesignVueResolver({
importStyle: false,
}),
ImportIconsResolver(),
VueUseDirectiveResolver(),
VueUseComponentsResolver(),
],
}),
AutoImport({
include: [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/],
imports: [
'vue',
'vue-router',
'@vueuse/core',
],
dts: 'src/types/auto-imports.d.ts',
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
ImportIcons({
collections: {
icons: path.resolve(__dirname, './src/assets/icons'),
},
// transform(svg, collection, icon) {
// // apply fill to this icon on this collection
// if (collection === 'icons' && icon === 'account') {
// return svg.replace(/^<svg /, '<svg fill="currentColor" ');
// }
// return svg;
// },
}),
Unocss({
shortcuts: {
'flex-center': 'flex items-center justify-center',
},
theme: {
colors: {
primary: '#1F76E5',
},
},
presets: [
presetAttributify(),
presetWind(),
],
transformers: [
transformerDirective(),
],
rules: [
[/^scrollbar-([^-]+)(-(.+))?$/, ([, d,, value], { rawSelector }) => {
let p = '';
if (!value) {
p = `width: ${d}; height: ${d}`;
}
if (d === 'w') {
p = `width: ${value}`;
} else if (p === 'h') {
p = `height: ${value}`;
}
return `.${rawSelector}::-webkit-scrollbar {
${p}
}`;
}],
// 文本超出省略
// usage: class="ellipsis ellipsis-2 ellipsis-3"
[/^ellipsis(-(\d*))?$/, ([,, d], { rawSelector }) => {
return `.${rawSelector} {${
Number(d) > 1
? `overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: ${d}; -webkit-box-orient: vertical;`
: 'overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'
}}`;
}],
],
}),
zipPack({
outDir: './',
outFileName: `${folderName}.zip`,
}),
],
});
};