-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
54 lines (51 loc) · 1.24 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
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable import/no-extraneous-dependencies */
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { resolve } from 'path';
import { render } from 'ejs';
import examples from './meta.json';
function injectHtml({ injectData = {}, injectOptions = {}, tags = [] } = {}) {
return {
name: 'vite:injectHtml',
transformIndexHtml: {
enforce: 'pre',
transform(html) {
return {
html: render(html, injectData, injectOptions),
tags,
};
},
},
};
}
const toCamelCase = (str) => {
const s =
str &&
str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map((x) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
.join('');
return s.slice(0, 1).toLowerCase() + s.slice(1);
};
export default {
plugins: [
injectHtml({
injectData: {
examples,
},
}),
svelte({ emitCss: false }),
],
build: {
rollupOptions: {
input: examples.reduce(
(o, x) => ({ ...o, [toCamelCase(x.path)]: resolve(__dirname, x.path, 'index.html') }),
{
main: resolve(__dirname, 'index.html'),
},
),
},
},
optimizeDeps: {
exclude: ['@marcellejs/backend'],
},
};