-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
33 lines (28 loc) · 758 Bytes
/
index.js
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
import { ComponentParser } from 'sveld'
import sveltePreprocess from 'svelte-preprocess'
import * as svelte from 'svelte/compiler'
import qs from 'query-string'
export default function sveld() {
return {
name: 'vite-plugin-sveld',
async transform(src, id) {
const query = qs.parse(id.split('?')[1])
if ('raw' in query && 'sveld' in query) {
const raw = JSON.parse(src.split('export default ')[1])
let { code } = await svelte.preprocess(raw, sveltePreprocess(), {
filename: id
})
const data = new ComponentParser({
verbose: false
}).parseSvelteComponent(code, {
filePath: id,
moduleName: id
})
return {
code: `export default ${JSON.stringify(data)}`,
map: null
}
}
}
}
}