-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
vite.config.js
43 lines (40 loc) · 1.08 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
40
41
42
43
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { readdir, rm, writeFile } from 'fs/promises';
// https://vitejs.dev/config/
export default defineConfig({
root: 'app',
build: {
outDir: '../static/svelte',
emptyOutDir: true,
assetsDir: '',
// sourcemap: 'inline', // enable for debugging
},
server: {
port: 4200,
},
plugins: [
svelte({
compilerOptions: {
customElement: true,
},
}),
syncToHugo()
]
})
function syncToHugo() {
return {
closeBundle: async () => {
const svelteBuild = './static/svelte';
const assets = await readdir(svelteBuild);
const js = assets.filter(name => name.match(/(index.)(?!.*?esm)(?!.*?css).*\w+/))[0];
const css = assets.filter(name => name.includes('.css'))[0];
const token = Math.floor(Math.random() * 69420);
await Promise.all([
writeFile(`./data/svelte.json`, JSON.stringify({ js, css, token })),
rm('./static/svelte/index.html')
]);
console.log(`wrote ${js} to hugo data`);
}
}
}