-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
vite.config.js
39 lines (35 loc) · 1.02 KB
/
vite.config.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
34
35
36
37
38
39
import process from 'node:process'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import Icons from 'unplugin-icons/vite'
import { defineConfig } from 'vite'
const options = process.env.CUSTOM_COMPILER === 'true'
? {
compiler: {
extension: 'svelte',
compiler: compilerFactory(),
},
}
: { compiler: 'svelte' }
export default defineConfig({
plugins: [
svelte(),
Icons(options),
],
})
function customSvelteCompiler(svg) {
const openTagStart = svg.indexOf('<svg ')
const openTagEnd = svg.indexOf('>', openTagStart)
const closeTagStart = svg.lastIndexOf('</svg')
const attributes = svg.slice(openTagStart + 5, openTagEnd)
const content = svg.slice(openTagEnd + 1, closeTagStart)
return `<script>
import CustomSvg from "/src/CustomSvg.svelte";
const content=\`${content.replace(/`/g, '`')}\`;
</script>
<CustomSvg ${attributes} {...$$props} {content}/>
`
}
// to show how to use async
async function compilerFactory() {
return Promise.resolve(customSvelteCompiler)
}