-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvite.config.ts
More file actions
87 lines (81 loc) · 1.99 KB
/
Copy pathvite.config.ts
File metadata and controls
87 lines (81 loc) · 1.99 KB
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
import {URL, fileURLToPath} from 'node:url'
import viteCompression from 'vite-plugin-compression'
import vue from '@vitejs/plugin-vue'
import vuetify, {transformAssetUrls} from 'vite-plugin-vuetify'
import {defineConfig} from 'vite'
import {type Plugin} from 'vite'
import postcss, {type Root} from 'postcss'
function vuetifyRemPlugin(): Plugin {
return {
name: 'vite-vuetify-to-rem',
transform(css: string, id: string) {
// Only process Vuetify .sass files
if (!id.startsWith('virtual:plugin-vuetify:components') && !id.includes('.sass')) return
return postcss([
(root: Root) => {
root.walkAtRules('media', rule => {
if (rule.params.includes('px')) {
rule.params = convertPxToRem(rule.params)
rule.walkDecls(decl => {
decl.value = convertPxToRem(decl.value)
})
}
})
},
])
.process(css, {from: id})
.then((result) => {
return {
code: result.css,
// map: result.map, // Optional: if you want to include source maps
}
})
},
}
}
// Function to convert px to rem
function convertPxToRem(value: string): string {
return value.replace(/(\d*\.?\d+)px/g, (match, p1) => {
const remValue = (parseFloat(p1) / 16).toFixed(3) // Convert px to rem
return `${remValue}rem`
})
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
viteCompression(),
vue({
template: {transformAssetUrls}
}),
vuetify({
autoImport: false,
styles: {
configFile: 'src/assets/styles/settings.scss'
}
}),
vuetifyRemPlugin()
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
extensions: [
'.js',
'.json',
'.mjs',
'.ts',
'.tsx',
'.vue'
]
},
css: {
preprocessorOptions: {
scss: {
api: 'modern'
}
}
},
server: {
port: 8080
}
})