forked from nomi-san/balance-buff-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
65 lines (60 loc) · 1.61 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
import path from 'node:path'
import fs from 'node:fs/promises'
import { defineConfig, Plugin } from 'vite';
import pkg from './package.json';
const BANNER = `/**
* @name ${pkg.name}
* @version ${pkg.version}
* @description ${pkg.description}
* @author ${pkg.author}
* @link ${pkg.repository.url}
*/`;
fs.writeFile(
path.join(__dirname, 'balance-buff-viewer.js'),
`${BANNER}\n\nexport * from 'https://cdn.skypack.dev/${pkg.name}?min';`
);
function imageIcons(): Plugin {
const virtualModuleId = 'virtual:icons'
const resolvedVirtualModuleId = '\0' + virtualModuleId
return {
name: 'icon-images',
resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId
}
},
async load(id) {
if (id === resolvedVirtualModuleId) {
const code = Array<string>();
const dir = path.join(__dirname, 'src/icons');
const files = await fs.readdir(dir);
for (const file of files.filter(n => /\.png$/i.test(n))) {
const name = path.parse(file).name;
const data = await fs.readFile(path.join(dir, file));
const bytes = Array.from(data);
code.push(`${name}: ${JSON.stringify(bytes)}`);
}
return `export const mime = 'image/png'; export default { ${code.join(',')} };`
}
},
}
}
export default defineConfig({
build: {
emptyOutDir: false,
rollupOptions: {
input: 'src/index.ts',
output: {
manualChunks: undefined,
entryFileNames: 'index.js',
}
}
},
esbuild: {
banner: BANNER,
legalComments: 'none'
},
plugins: [
imageIcons()
]
});