-
Notifications
You must be signed in to change notification settings - Fork 14
/
vite.config.ts
68 lines (65 loc) · 1.75 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
66
67
68
import { sveltekit } from '@sveltejs/kit/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import { FileSystemIconLoader } from 'unplugin-icons/loaders';
import Icons from 'unplugin-icons/vite';
import { defineConfig } from 'vitest/config';
import type { Plugin } from 'vite';
import fs from 'fs';
function raw_fonts(ext: string[]) {
return {
name: 'vite-plugin-raw-fonts',
transform(_code: string, id: string) {
if (ext.some((e) => id.endsWith(e))) {
const buffer = fs.readFileSync(id);
return { code: `export default ${JSON.stringify(buffer)}`, map: null };
}
},
};
}
function coep_plugin(): Plugin {
return {
name: 'cross-origin-plugin',
configureServer(server) {
server.middlewares.use((_, res, next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
next();
});
},
configurePreviewServer(server) {
server.middlewares.use((_, res, next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
next();
});
},
};
}
export default defineConfig({
plugins: [
sveltekit(),
Icons({
compiler: 'svelte',
customCollections: {
'material-icon-theme': FileSystemIconLoader('./node_modules/material-icon-theme/icons'),
'r-icons': FileSystemIconLoader('./src/lib/icons/Rinconx64_r-icons'),
sveltelab: FileSystemIconLoader('./src/lib/icons/sveltelab'),
},
}),
visualizer({
emitFile: true,
filename: 'stats.html',
}),
raw_fonts(['.ttf']),
coep_plugin(),
],
resolve: {
dedupe: ['@codemirror/state'],
},
define: {
'process.env.NODE_ENV': '"production"',
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
},
});