forked from keplergl/kepler.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
56 lines (49 loc) · 1.46 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
56 lines (49 loc) · 1.46 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as esbuild from 'esbuild';
import path from 'path';
import {fileURLToPath} from 'url';
import {createRequire} from 'module';
const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const isWatch = process.argv.includes('--watch');
// Resolve apache-arrow to a single location
const arrowPath = path.dirname(require.resolve('apache-arrow'));
// Resolve browser polyfills for Node.js built-ins (point to actual entry files)
const assertPath = require.resolve('assert/');
const eventsPath = require.resolve('events/');
const buildOptions = {
entryPoints: {widget: 'src/index.ts'},
bundle: true,
format: 'esm',
outdir: 'keplergl/static',
loader: {
'.ts': 'ts',
'.tsx': 'tsx',
'.css': 'css'
},
external: [],
minify: !isWatch,
sourcemap: isWatch,
target: ['es2020'],
define: {
'process.env.NODE_ENV': isWatch ? '"development"' : '"production"',
'global': 'globalThis'
},
inject: ['./src/process-shim.js'],
// Use alias to ensure single instance of apache-arrow and provide browser polyfills
alias: {
'apache-arrow': arrowPath,
'assert': assertPath,
'events': eventsPath
}
};
async function build() {
if (isWatch) {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
console.log('Watching for changes...');
} else {
await esbuild.build(buildOptions);
console.log('Build complete!');
}
}
build().catch(() => process.exit(1));