-
Notifications
You must be signed in to change notification settings - Fork 17
/
vite.config.ts
36 lines (33 loc) · 930 Bytes
/
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
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import MagicString from "magic-string";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
worker: {
plugins: [transformImports()]
},
build: {
sourcemap: true
},
})
function transformImports() {
return {
name: 'transform-imports',
transform(src, id) {
// Resolves some issues that come from developing with web worker modules
// But building without them.
let s: MagicString = new MagicString(src);
s.replace(/import\("(.*?)"\)/, (_, library) => {
if (library == 'module') return 'self'
s.prepend(`import libUrl from "${library}?url";\n`)
return 'importScripts(libUrl);Promise.resolve()'
})
s.replace('import.meta.url', '""')
return {
code: s.toString(),
map: s.generateMap(),
}
}
}
}