forked from atlassian/better-ajv-errors
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
executable file
·52 lines (47 loc) · 1.1 KB
/
build.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
#!/usr/bin/env node
const process = require('process');
const isCI = require('is-ci');
const fg = require('fast-glob');
const esbuild = require('esbuild');
const isEsmBuild = process.argv[2] !== '--cjs';
const config = {
cjs: {
format: 'cjs',
platform: 'node',
outdir: './lib/cjs',
},
esm: {
format: 'esm',
outdir: './lib/esm',
outExtension: {
'.js': '.mjs',
},
bundle: true,
plugins: [
{
name: 'add-mjs',
setup(build) {
build.onResolve({ filter: /.*/ }, args => {
if (args.kind === 'entry-point') return;
let path = args.path;
if (path.startsWith('.') && !path.endsWith('.mjs')) path += '.mjs';
return { path, external: true };
});
},
},
],
},
};
fg('src/**/*.js', {
ignore: ['**/__tests__', '**/__fixtures__'],
})
.then(entryPoints =>
esbuild.build({
...(isEsmBuild ? config.esm : config.cjs),
entryPoints,
sourcemap: true,
logLevel: isCI ? 'silent' : 'info',
target: 'node12.13',
})
)
.catch(_ => process.exit(1));