-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
39 lines (37 loc) · 1.08 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
import { sveltekit } from '@sveltejs/kit/vite';
import { svelteTesting } from '@testing-library/svelte/vite';
import { readFile } from 'fs/promises';
import { defineConfig, type Plugin } from 'vitest/config';
function packagePluginFactory(file: 'pkg' | 'pkg-lock'): Plugin {
const pluginName = file === 'pkg' ? 'packageJson' : 'packageLockJson';
const fileName = file === 'pkg' ? 'package.json' : 'package-lock.json';
return {
name: pluginName,
resolveId: {
order: 'pre',
handler(source, importer, options) {
if (source === pluginName) {
return source;
}
return null;
},
},
load: {
order: 'pre',
async handler(id, options) {
if (id === pluginName) {
return `export default ${(await readFile(`./${fileName}`, { encoding: 'utf-8' }))}`;
}
return null;
},
}
};
}
export default defineConfig({
plugins: [sveltekit(), packagePluginFactory('pkg'), packagePluginFactory('pkg-lock'), svelteTesting()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}', 'src/**/*.{test,spec}.svelte.{js,ts}'],
environment: 'jsdom',
globals: true
}
});