-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.mjs
More file actions
42 lines (38 loc) · 1.16 KB
/
esbuild.mjs
File metadata and controls
42 lines (38 loc) · 1.16 KB
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
import glob from 'tiny-glob';
import { build } from 'esbuild';
import esbuildSvelte from 'esbuild-svelte';
import sveltePreprocess from 'svelte-preprocess';
import { windi } from 'svelte-windicss-preprocess';
import { writeFileSync } from 'fs';
import { join } from 'path';
const OUTPUT_DIR = 'components';
glob('src/components/**/*.wc.svelte').then((components) => {
const buildData = components.map((component) => ({
entry: component,
output: component.split('/').reverse()[0].replace('.wc.svelte', '.js'),
}));
buildData.forEach(({ entry, output }) =>
build({
entryPoints: [entry],
outfile: join(OUTPUT_DIR, output),
bundle: true,
inject: ['src/utils/custom-element.js'],
plugins: [
esbuildSvelte({
preprocess: [
windi({
configPath: 'windi.config.js',
mode: 'prod',
}),
sveltePreprocess(),
],
compileOptions: { customElement: true },
}),
],
}).catch(() => process.exit(1)),
);
writeFileSync(
join(OUTPUT_DIR, 'index.js'),
buildData.map(({ output }) => `import './${output}';\n`).join(''),
);
});