-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
113 lines (109 loc) · 2.87 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
import { fileURLToPath, URL } from 'node:url'
import path from 'node:path'
import legacy from '@vitejs/plugin-legacy'
import vue from '@vitejs/plugin-vue'
import jsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import uno from 'unocss/vite'
import Components from 'unplugin-vue-components/vite'
import svg from 'vite-svg-loader'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig, loadEnv } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import { configDefaults } from 'vitest/config'
import { viteVConsole as vconsole } from 'vite-plugin-vconsole'
function legacySupportEnabled(mode: string) {
const envRecords = loadEnv(mode, process.cwd())
return envRecords.VITE_LEGACY === 'true'
}
function pwaSupportEnabled(mode: string) {
const envRecords = loadEnv(mode, process.cwd())
return envRecords.VITE_PWA_ENABLED === 'true'
}
const legacyTarget = ['Chrome 64']
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler', // or "modern"
},
},
},
build: {
target: legacySupportEnabled(mode) ? legacyTarget : undefined,
terserOptions: {
compress:
mode === 'production'
? {
drop_console: true,
drop_debugger: true,
}
: false,
},
},
plugins: [
vue(),
jsx(),
uno(),
Components({
resolvers: [VantResolver(), IconsResolver()],
dts: 'src/types/components.d.ts',
}),
AutoImport({
eslintrc: {
enabled: true,
filepath: '.eslintrc-auto-import.json',
},
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
imports: ['vue', 'vue-router', 'vitest'],
dts: 'src/types/auto-imports.d.ts',
}),
vconsole({
entry: path.resolve('src/main.ts'), // or you can use entry: [path.resolve('src/main.ts')]
enabled: mode !== 'production',
}),
Icons({
scale: 1,
}),
svg({
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
],
},
}),
pwaSupportEnabled(mode) &&
VitePWA({
registerType: 'autoUpdate',
manifest: {
theme_color: '#ffffff',
},
}),
legacySupportEnabled(mode) &&
legacy({
targets: legacyTarget,
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
globals: true,
passWithNoTests: true,
},
}))