-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesBuild.ts
49 lines (44 loc) · 1.08 KB
/
esBuild.ts
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
import { build } from 'esbuild';
import { globSync } from 'glob';
import semver from 'semver';
import { engines } from './package.json';
import { esbuildPluginBrowserslist } from 'esbuild-plugin-browserslist';
import browserslist from 'browserslist';
const entryPoints = globSync('src/**/!(*.d).ts', { cwd: __dirname });
const nodeVersion = semver.minVersion(engines.node, { loose: false })?.version;
if (!nodeVersion) {
throw new Error('Missing engines.node version from package.json');
}
void build({
bundle: false,
sourcemap: false,
platform: 'node',
target: `node${nodeVersion}`,
outdir: 'src',
format: 'cjs',
entryPoints,
});
void build({
bundle: false,
sourcemap: false,
platform: 'node',
target: `node${nodeVersion}`,
outdir: 'src',
format: 'esm',
outExtension: {
'.js': '.mjs',
},
entryPoints,
});
void build({
bundle: true,
platform: 'browser',
format: 'esm',
plugins: [
esbuildPluginBrowserslist(browserslist('defaults'), {
printUnknownTargets: false,
}),
],
outfile: 'src/browser.js',
entryPoints: ['src/index.ts'],
});