-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathvitest.config.ts
37 lines (33 loc) · 1.19 KB
/
vitest.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
import { defineConfig, mergeConfig } from 'vitest/config'
import path from 'path'
import config from './electron.vite.config'
export const nodejsPolarsDirnamePlugin = () => {
const name = 'nodejs-polars-dirname-plugin'
return {
name,
transform(code: string, id: string) {
// aim for the node_modules/nodejs-polars/bin/native-polars.js file
if (id.endsWith('.node')) {
const file = path.basename(id)
return `
// create a custom require function to load .node files
import { createRequire } from 'module';
const customRequire = createRequire(import.meta.url)
// load the .node file expecting it to be in the same directory as the output bundle
const content = customRequire('./${file}')
// export the content straight back out again
export default content
`
}
// else return the original code (leave code unrelated to nodejs-polars untouched)
return code
}
}
}
//export default mergeConfig(config.main as any, defineConfig({
export default defineConfig({
test: {
// ...
},
plugins: [nodejsPolarsDirnamePlugin()]
})