-
Notifications
You must be signed in to change notification settings - Fork 31
/
esbuild.prod.mjs
61 lines (59 loc) · 1.64 KB
/
esbuild.prod.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
// @ts-check
import path from "path";
import browserslist from "browserslist";
import esbuild from "esbuild";
import { esbuildPluginBrowserslist } from "esbuild-plugin-browserslist";
import browserListConfig from "./packages/browserslist-config-jkl/index.js";
/**
*
* @param {string} outbase
* @param {"esm" | "cjs"} format
* @returns
*/
const createConfig = (outbase, format) => {
return [
{
bundle: false,
minify: false,
outdir: path.join(outbase, format),
sourcemap: true,
format,
plugins: [
esbuildPluginBrowserslist(browserslist(browserListConfig), {
printUnknownTargets: false,
}),
],
},
];
};
/**
* @param {{ entryPoints: string[], outdir: string } | Array<{ entryPoints: string[], outdir: string }>} options - Send entrypoints til esbuild
* @example
* await build({
* entryPoints: ["src/index.ts"],
* outdir: "dist",
* });
*/
export async function build(options) {
const opts = Array.isArray(options) ? options : [options];
try {
await Promise.all(
opts.flatMap((o) => [
createConfig(o.outdir, "esm").flatMap((esm) =>
esbuild.build({
...o,
...esm,
}),
),
createConfig(o.outdir, "cjs").flatMap((cjs) =>
esbuild.build({
...o,
...cjs,
}),
),
]),
);
} catch (e) {
process.exit(1);
}
}