forked from typingbeaver/snake-label
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.singlefile.js
More file actions
49 lines (46 loc) · 1.34 KB
/
Copy pathvite.config.singlefile.js
File metadata and controls
49 lines (46 loc) · 1.34 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
// vite.config.singlefile.js
import { defineConfig } from 'vite'
import { viteSingleFile } from 'vite-plugin-singlefile'
import { readFileSync } from 'fs'
import { resolve } from 'path'
const mimeTypes = {
svg: 'image/svg+xml',
png: 'image/png',
webp: 'image/webp',
jpg: 'image/jpeg',
jpeg: 'image/jpeg',
}
function inlinePublicImages() {
return {
name: 'inline-public-images',
transformIndexHtml: {
order: 'pre',
handler(html) {
return html.replace(
/src="((?!data:)[^"]+\.(svg|png|webp|jpg|jpeg))"/g,
(match, src) => {
try {
const content = readFileSync(resolve(process.cwd(), 'public', src))
const ext = src.split('.').pop()
return `src="data:${mimeTypes[ext]};base64,${content.toString('base64')}"`
} catch {
return match
}
}
)
}
}
}
}
export default defineConfig({
build: {},
css: {
postcss: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
}
},
plugins: [inlinePublicImages(), viteSingleFile()],
})