forked from ZJONSSON/parquetjs
-
Notifications
You must be signed in to change notification settings - Fork 25
/
esbuild.mjs
81 lines (79 loc) · 2.05 KB
/
esbuild.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import esbuild from 'esbuild';
import watPlugin from 'esbuild-plugin-wat';
import { compressionBrowserPlugin } from './esbuild-plugins.mjs';
// esbuild has TypeScript support by default
const baseConfig = {
bundle: true,
entryPoints: ['parquet.ts'],
define: {
'process.env.NODE_DEBUG': 'false',
'process.env.NODE_ENV': '"production"',
global: 'window',
},
inject: ['./esbuild-shims.mjs'],
minify: true,
mainFields: ['browser', 'module', 'main'],
platform: 'browser', // default
plugins: [compressionBrowserPlugin, watPlugin()],
target: 'es2020', // default
};
// configuration for generating test code in browser
const testConfig = {
bundle: true,
entryPoints: ['test/browser/main.ts'],
define: {
'process.env.NODE_DEBUG': 'false',
'process.env.NODE_ENV': '"production"',
global: 'window',
},
inject: ['./esbuild-shims.mjs'],
minify: false,
mainFields: ['browser', 'module', 'main'],
platform: 'browser', // default
plugins: [compressionBrowserPlugin, watPlugin()],
target: 'es2020', // default
};
const targets = [
{
...baseConfig,
globalName: 'parquetjs',
outdir: './dist/browser',
},
{
...baseConfig,
format: 'esm',
outfile: 'dist/browser/parquet.esm.js',
},
{
...baseConfig,
format: 'cjs',
outfile: 'dist/browser/parquet.cjs.js',
},
];
// Browser test code below is only in ESM
const testTargets = [
{
...testConfig,
format: 'esm',
mainFields: ['module', 'main'],
outfile: 'test/browser/main.js',
},
];
Promise.all(targets.map(esbuild.build))
.then((results) => {
if (results.reduce((m, r) => m && !r.warnings.length, true)) {
console.log('built dist targets with no errors or warnings');
}
})
.then(() => {
return Promise.all(testTargets.map(esbuild.build));
})
.then((results) => {
if (results.reduce((m, r) => m && !r.warnings.length, true)) {
console.log('built test targets with no errors or warnings');
}
})
.catch((e) => {
console.error('Finished with errors: ', e.toString());
process.exit(1);
});