-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.mjs
73 lines (68 loc) · 1.98 KB
/
build.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
62
63
64
65
66
67
68
69
70
71
72
73
import esbuild from "esbuild"
import packageJson from './package.json' assert { type: 'json' };
const external = ["dotenv", "@grpc/grpc-js"]
// ESM for browser
esbuild.buildSync({
entryPoints: ["bxsolana/index.browser.ts"],
platform: "browser",
format: "esm",
sourcemap: true,
bundle: true,
outfile: "dist/browser/index.js",
external,
define: {
'process.env.PACKAGE_NAME': JSON.stringify(packageJson.name),
'process.env.PACKAGE_VERSION': JSON.stringify(packageJson.version),
},
})
// CJS for browser
esbuild.buildSync({
entryPoints: ["bxsolana/index.browser.ts"],
platform: "browser",
format: "cjs",
sourcemap: true,
bundle: true,
outfile: "dist/browser/index.cjs",
external,
define: {
'process.env.PACKAGE_NAME': JSON.stringify(packageJson.name),
'process.env.PACKAGE_VERSION': JSON.stringify(packageJson.version),
},
})
// ESM for node
esbuild.buildSync({
entryPoints: ["bxsolana/index.ts"],
platform: "node",
format: "esm",
sourcemap: true,
bundle: true,
// not entirely sure what this snippet does: https://github.com/evanw/esbuild/issues/1921
banner: {
js: `
import { createRequire } from 'module';
import path from 'path';
import { fileURLToPath } from 'url';
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
`,
},
outfile: "dist/node/index.js",
define: {
'process.env.PACKAGE_NAME': JSON.stringify(packageJson.name),
'process.env.PACKAGE_VERSION': JSON.stringify(packageJson.version),
},
})
// CJS for node
esbuild.buildSync({
entryPoints: ["bxsolana/index.ts"],
platform: "node",
format: "cjs",
sourcemap: true,
bundle: true,
outfile: "dist/node/index.cjs",
define: {
'process.env.PACKAGE_NAME': JSON.stringify(packageJson.name),
'process.env.PACKAGE_VERSION': JSON.stringify(packageJson.version),
},
})