-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
40 lines (37 loc) · 1.31 KB
/
esbuild.config.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
/* eslint-disable no-unused-vars */
import { build } from "esbuild";
import process from "process";
import console from "node:console";
import { readFileSync } from "fs";
// eslint-disable-next-line no-undef
const { dependencies } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url)));
const production = process.argv[2] === "--production";
const cjs = build({
entryPoints: ["./src/index.js"],
bundle: true,
platform: "node",
format: "cjs",
external: Object.keys(dependencies),
watch: production ? false : {
onRebuild(error, result) {
if (error) {
console.error(`[watch] building node cjs failed:`, error);
} else {
const { stop, ...alerts } = result;
console.log(`[watch] built node cjs:`, alerts);
}
},
},
target: "es2020",
banner: {
js: "/* This is a bundled file generated by esbuild\nIf you want to view the source, please visit the github repository */",
},
outfile: "./dist/index.cjs",
}).then((result) => {
const { stop, ...alerts } = result;
console.log(`built node cjs:`, alerts);
}).catch((error) => {
console.error(`building node cjs failed:`, error);
process.exit(1);
});
if (!production) cjs.then(() => console.log("watch mode enabled..."));