-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
80 lines (70 loc) · 2.08 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
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import type { UserConfigExport } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueMacros from 'unplugin-vue-macros'
import { viteMockServe } from '@lincy/vite-plugin-mock'
import UnoCSS from 'unocss/vite'
import Components from './vite.config.components'
import PWA from './vite.config.pwa'
import Build from './vite.config.build'
function charsetRemoval() {
return {
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule: any) => {
if (atRule.name === 'charset') {
atRule.remove()
}
},
},
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const __dirname = path.dirname(fileURLToPath(import.meta.url))
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
const localMock = true
const config: UserConfigExport = {
base: '/',
plugins: [
VueMacros.vite({
plugins: {
vue: vuePlugin({
template: {
compilerOptions: {
isCustomElement: tag => ['def'].includes(tag),
},
},
}),
vueJsx: vueJsx(),
},
}),
viteMockServe({
mockPath: 'mock',
enable: command === 'serve' && localMock,
logger: true,
}),
...Components(),
UnoCSS({}),
...PWA(),
],
resolve: {
alias: {
'@': path.join(__dirname, './src'),
},
},
...Build,
css: {
postcss: {
plugins: [
charsetRemoval(),
],
},
},
}
return config
})