-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
48 lines (41 loc) · 1.15 KB
/
esbuild.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
#!/usr/bin/env node
import { context } from 'esbuild';
const ctx = await context({
bundle: true,
color: true,
entryPoints: ['resources/js/components/geocoder.js'],
format: 'esm',
mainFields: ['module', 'main'],
minify: true,
outfile: './dist/mapbox.js',
platform: 'browser',
target: ['es2020'],
treeShaking: true,
plugins: [
{
name: 'watcher',
setup(build) {
build.onStart(() => {
const outfile = build.initialOptions.outfile;
const now = new Date(Date.now()).toLocaleTimeString();
console.log(`⏱️ Build started at ${now}: ${outfile}`);
});
build.onEnd(result => {
const outfile = build.initialOptions.outfile;
const now = new Date(Date.now()).toLocaleTimeString();
if (result.errors.length > 0) {
return console.error(`🚫 Build failed at ${now}: ${outfile}`);
}
console.log(`✅ Build finished at ${now}: ${outfile}`);
});
},
},
],
});
// eslint-disable-next-line no-undef
if (process.argv.includes('--watch')) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}