forked from shuaiplus/nodecrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mjs
More file actions
75 lines (67 loc) · 1.67 KB
/
vite.config.mjs
File metadata and controls
75 lines (67 loc) · 1.67 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
import { defineConfig } from 'vite';
import { splitVendorChunkPlugin } from 'vite';
import { viteSingleFile } from 'vite-plugin-singlefile';
import fs from 'node:fs';
function inlineFavicon() {
const svg = fs.readFileSync('client/assets/favicon.svg', 'utf-8');
const encoded = 'data:image/svg+xml;base64,' + Buffer.from(svg).toString('base64');
return {
name: 'inline-favicon',
enforce: 'post',
generateBundle(_, bundle) {
for (const fileName in bundle) {
const file = bundle[fileName];
if (file.type === 'asset' && file.fileName.endsWith('.html')) {
file.source = file.source.replace(
/<link[^>]+rel=["']icon["'][^>]*>/,
`<link rel="icon" href="${encoded}">`
);
}
if (
file.type === 'asset' &&
file.fileName.includes('favicon') &&
file.fileName.endsWith('.svg')
) {
delete bundle[fileName];
}
}
}
};
}
export default defineConfig(({ mode }) => {
const isSingleFile = mode === 'singlefile';
return {
root: 'client',
base: './',
plugins: isSingleFile
? [viteSingleFile(), inlineFavicon()]
: [splitVendorChunkPlugin()],
build: {
outDir: '../dist',
emptyOutDir: true,
minify: 'esbuild',
assetsInlineLimit: isSingleFile ? Number.MAX_SAFE_INTEGER : undefined,
rollupOptions: {
input: 'client/index.html',
output: isSingleFile
? undefined
: {}
},
sourcemap: false,
cssCodeSplit: !isSingleFile,
chunkSizeWarningLimit: 1000,
},
resolve: {
alias: {
buffer: 'buffer',
},
},
server: {
hmr: true,
open: true,
},
optimizeDeps: {
include: ['buffer'],
},
};
});