-
Notifications
You must be signed in to change notification settings - Fork 14
/
esbuild.config.mjs
33 lines (30 loc) · 961 Bytes
/
esbuild.config.mjs
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
import 'dotenv/config';
import esbuild from 'esbuild';
const context = await esbuild.context({
entryPoints: ['src/client/index.tsx', 'src/client/style.css', 'src/client/serviceWorker.ts'],
outdir: 'dist/public',
minify: process.env.NODE_ENV === 'production',
bundle: true,
sourcemap: true,
format: 'esm',
treeShaking: true,
define: Object.fromEntries(Object.keys(process.env).map(key => [`process.env.${key}`, `"${process.env[key]}"`])),
plugins: [reporterPlugin()],
loader: { '.svg': 'dataurl', '.txt': 'text', '.md': 'text' },
});
if (process.argv.includes('--watch')) {
console.log('Watching ...');
await context.watch();
} else {
console.log('Building ...');
await context.rebuild();
await context.dispose();
}
function reporterPlugin() {
return {
name: 'reporter',
setup(build) {
build.onEnd(result => console.log(`Done - ${result.errors.length} errors, ${result.warnings.length} warnings`));
},
};
}