-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathesbuild.js
More file actions
65 lines (60 loc) · 1.53 KB
/
esbuild.js
File metadata and controls
65 lines (60 loc) · 1.53 KB
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
const esbuild = require('esbuild');
const glob = require('glob');
const { replace } = require('esbuild-plugin-replace');
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
const stdLibBrowser = require('node-stdlib-browser');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const files = glob
.sync('./src/**/*.ts')
.filter((file) => !file.includes('/tests/') && !file.includes('/stories/'));
const commonConfig = {
entryPoints: files,
platform: 'node',
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer'
},
plugins: [
plugin(stdLibBrowser),
nodeExternalsPlugin(),
replace({
__sdkDappVersion: process.env.npm_package_version
})
]
};
async function build() {
try {
// ESM build
await esbuild.build({
...commonConfig,
splitting: true,
format: 'esm',
outdir: 'out',
bundle: true,
minify: true,
sourcemap: true,
chunkNames: '__chunks__/[name]-[hash]',
target: ['es2021'],
outExtension: { '.js': '.mjs' },
tsconfig: './tsconfig.esm.json'
});
console.log('[Build] ✅ ESM build completed');
// CJS build
await esbuild.build({
...commonConfig,
format: 'cjs',
outdir: 'out',
minify: true,
sourcemap: true,
target: ['es2021'],
outExtension: { '.js': '.cjs' },
tsconfig: './tsconfig.cjs.json'
});
console.log('[Build] ✅ CJS build completed');
} catch (err) {
console.error(err);
process.exit(1);
}
}
build();