/
vite.config.js
60 lines (56 loc) · 1.36 KB
/
vite.config.js
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
const MagicString = require('magic-string')
/**
* @type {import('vite').UserConfig}
*/
module.exports = {
resolve: {
alias: {
'@': __dirname
}
},
css: {
preprocessorOptions: {
less: {
additionalData: '@color: red;'
},
styl: {
additionalData: (content, filename) => {
const ms = new MagicString(content, { filename })
const willBeReplaced = 'blue-red-mixed'
const start = content.indexOf(willBeReplaced)
ms.overwrite(start, start + willBeReplaced.length, 'purple')
const map = ms.generateMap({ hires: true })
map.file = filename
map.sources = [filename]
return {
content: ms.toString(),
map
}
}
}
}
},
build: {
sourcemap: true
},
plugins: [
{
name: 'virtual-html',
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
if (req.url === '/virtual.html') {
const t = await server.transformIndexHtml(
'/virtual.html',
'<style> .foo { color: red; } </style> <p class="foo">virtual html</p>'
)
res.setHeader('Content-Type', 'text/html')
res.statusCode = 200
res.end(t)
return
}
next()
})
}
}
]
}