-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
59 lines (54 loc) · 1.62 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
53
54
55
56
57
58
59
// Copyright (C) 2024, Nuklai. All rights reserved.
// See the file LICENSE for licensing terms.
import { build } from "esbuild";
import path from "path";
import { fileURLToPath } from "url";
import alias from "esbuild-plugin-alias";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
// Convert import.meta.url to __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const commonOptions = {
entryPoints: ["./src/index.ts"],
bundle: true,
sourcemap: true,
target: "esnext",
define: {
"process.env.NODE_ENV": JSON.stringify("production")
},
inject: ["./polyfills.js"],
outdir: "dist"
};
const builds = [
{
...commonOptions,
platform: "browser",
format: "esm",
entryNames: "[name].esm",
plugins: [
alias({
crypto: path.resolve(
__dirname,
"node_modules/crypto-browserify/index.js"
),
stream: path.resolve(
__dirname,
"node_modules/stream-browserify/index.js"
),
buffer: path.resolve(__dirname, "node_modules/buffer/index.js"),
zlib: path.resolve(__dirname, "node_modules/browserify-zlib/index.js"),
util: path.resolve(__dirname, "node_modules/util/util.js"),
process: path.resolve(__dirname, "node_modules/process/browser.js"),
events: path.resolve(__dirname, "node_modules/events/events.js")
}),
NodeModulesPolyfillPlugin()
]
},
{
...commonOptions,
platform: "node",
format: "cjs",
entryNames: "[name].cjs"
}
];
Promise.all(builds.map(build)).catch(() => process.exit(1));