-
Notifications
You must be signed in to change notification settings - Fork 3
/
esbuild.config.js
67 lines (50 loc) · 1.29 KB
/
esbuild.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
55
56
57
58
59
60
61
62
63
64
65
66
67
import { argv } from 'node:process';
import * as esbuild from 'esbuild';
const
productionMode = ('development' !== (argv[2] || process.env.NODE_ENV)),
target = 'chrome100,firefox100,safari15'.split(',');
console.log(`${ productionMode ? 'production' : 'development' } build`);
// bundle CSS
const buildCSS = await esbuild.context({
entryPoints: [ './src/css/main.css' ],
bundle: true,
target,
external: ['/images/*'],
loader: {
'.png': 'file',
'.jpg': 'file',
'.svg': 'dataurl'
},
logLevel: productionMode ? 'error' : 'info',
minify: productionMode,
sourcemap: !productionMode && 'linked',
outdir: './build/css'
});
// bundle JS
const buildJS = await esbuild.context({
entryPoints: [ './src/js/main.js' ],
format: 'esm',
bundle: true,
target,
drop: productionMode ? ['debugger', 'console'] : [],
logLevel: productionMode ? 'error' : 'info',
minify: productionMode,
sourcemap: !productionMode && 'linked',
outdir: './build/js'
});
if (productionMode) {
// single production build
await buildCSS.rebuild();
buildCSS.dispose();
await buildJS.rebuild();
buildJS.dispose();
}
else {
// watch for file changes
await buildCSS.watch();
await buildJS.watch();
// development server
await buildCSS.serve({
servedir: './build'
});
}