-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.mjs
executable file
·46 lines (39 loc) · 1.12 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
import ESBUILD from "esbuild";
import glob from "glob";
import path from "path";
const fileExtensions = "js,ts";
const outputFolder = argv("outputFolder");
const entryFolder = argv("entryFolder");
const watch = argv("watch") === true;
process.env.NODE_ENV =
argv("production") === true ? "production" : "development";
const files = glob
.sync(`${entryFolder}/main.{${fileExtensions}}`)
.map((entry) => path.basename(entry))
.filter((name) => !name.startsWith("_"));
files.forEach((file) => {
ESBUILD.build({
entryPoints: [`${entryFolder}/${file}`],
watch,
outdir: outputFolder,
sourcemap: true,
bundle: true,
//minify: true,
platform: "browser",
logLevel: "info",
legalComments: "linked",
target: "es2017",
});
});
function argv(key) {
// Return true if the key exists and a value is defined
if (process.argv.includes(`--${key}`)) {
return true;
}
const value = process.argv.find((element) => element.startsWith(`--${key}=`));
// Return null if the key does not exist and a value is not defined
if (!value) {
return null;
}
return value.replace(`--${key}=`, "");
}