-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
122 lines (109 loc) · 3.34 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
/// <reference types="vitest" />
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import UniPages from '@uni-helper/vite-plugin-uni-pages'
import UniLayouts from '@uni-helper/vite-plugin-uni-layouts'
import VueDevTools from 'vite-plugin-vue-devtools'
import ReactivityTransform from '@vue-macros/reactivity-transform/vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
// 将px转换为vw的工具包
import pxToViewport from 'postcss-px-to-viewport-8-plugin'
const vw = pxToViewport({
unitToConvert: 'px', // 要转化的单位
viewportWidth: 375, // UI设计稿的宽度
unitPrecision: 6, // 转换后的精度,即小数点位数
propList: ['*'], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
selectorBlackList: ['ignore'], // 指定不转换为视窗单位的类名,
minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
replace: true, // 是否转换后直接更换属性值
exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
landscape: false, // 是否处理横屏情况
})
// https://vitejs.dev/config/
export default defineConfig(async () => {
const Unocss = (await import('unocss/vite')).default
return {
resolve: {
alias: {
'@/': `${resolve(__dirname, 'src')}/`,
},
},
plugins: [
vueJsx,
/**
* vite-plugin-uni-pages
* @see https://github.com/uni-helper/vite-plugin-uni-pages
*/
UniPages({
subPackages: [
'src/pages-sub',
],
}),
/**
* vite-plugin-uni-layouts
* @see https://github.com/uni-helper/vite-plugin-uni-layouts
*/
UniLayouts(),
/**
* unocss
* @see https://github.com/antfu/unocss
* see unocss.config.ts for config
*/
Unocss(),
/**
* unplugin-auto-import 按需 import
* @see https://github.com/antfu/unplugin-auto-import
*/
AutoImport({
imports: [
'vue',
'uni-app',
],
dts: true,
dirs: [
'./src/composables',
],
vueTemplate: true,
}),
/**
* unplugin-vue-components 按需引入组件
* 注意:需注册至 uni 之前,否则不会生效
* @see https://github.com/antfu/vite-plugin-components
*/
Components({
dts: 'src/components.d.ts',
}),
/**
* vite-plugin-vue-devtools 增强 Vue 开发者体验
* @see https://github.com/webfansplz/vite-plugin-vue-devtools
*/
VueDevTools(),
uni(),
/**
* Reactivity Transform
* @see https://vue-macros.sxzz.moe/zh-CN/features/reactivity-transform.html
*/
ReactivityTransform(),
],
css: {
postcss: {
plugins: [
vw,
],
},
},
/**
* Vitest
* @see https://github.com/vitest-dev/vitest
*/
test: {
environment: 'jsdom',
},
}
})