-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
75 lines (72 loc) · 1.76 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { transform } from 'esbuild';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import pkg from './package.json';
const bundleComponents = false;
// https://vitejs.dev/config/
export default defineConfig({
root: './packages/lib/',
build: {
outDir: '../../dist/lib',
emptyOutDir: true,
lib: {
entry: './index.ts',
formats: bundleComponents ? (['es', 'esm', 'umd'] as any) : ['es'],
name: pkg.name.replace(/-./g, (char) => char[1].toUpperCase()),
fileName: (format) =>
({
es: `${pkg.name}.js`,
esm: `${pkg.name}.min.js`,
umd: `${pkg.name}.umd.js`
})[format]
},
rollupOptions: {
output: bundleComponents
? {}
: {
inlineDynamicImports: false,
chunkFileNames: '[name].js',
manualChunks: { svelte: ['svelte'] }
}
}
},
plugins: [
svelte({
exclude: /\.wc\.svelte$/ as any,
compilerOptions: {
customElement: false
}
}),
svelte({
include: /\.wc\.svelte$/ as any
}),
viteStaticCopy({
targets: [
{
src: './src/types/',
dest: '../../dist/lib/'
}
]
}),
minifyEs()
]
});
// Workaround for https://github.com/vitejs/vite/issues/6555
function minifyEs() {
return {
name: 'minifyEs',
renderChunk: {
order: 'post' as const,
async handler(code, chunk, outputOptions) {
if (
outputOptions.format === 'es' &&
(!bundleComponents || chunk.fileName.endsWith('.min.js'))
) {
return await transform(code, { minify: true });
}
return code;
}
}
};
}