-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.ts
42 lines (35 loc) · 1.07 KB
/
esbuild.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
import { BuildOptions, build, context } from 'esbuild';
import { copyFile, mkdir } from 'node:fs/promises';
const config: BuildOptions = {
entryPoints: ['src/index.js'],
bundle: true,
outdir: 'umd',
jsx: 'automatic',
format: 'esm',
minify: true,
sourcemap: true,
loader: { '.css': 'text' },
alias: {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat', // Must be below test-utils
'react/jsx-runtime': 'preact/jsx-runtime',
},
};
await mkdir('lib/', { recursive: true });
await mkdir('umd/', { recursive: true });
await copyFile('src/index.html', 'umd/index.html');
const devMode = process.argv.includes('--dev');
if (devMode) {
let ctx = await context(config);
let { host, port } = await ctx.serve({
servedir: 'umd',
});
console.log({ host, port });
} else {
// UMD build
let result = await build(config);
// Importable NPM build (ESM)
let resultUmd = await build({ ...config, external: ['preact', 'preact/hooks'], outdir: 'lib' });
console.log(process.argv, result, resultUmd);
}