-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
53 lines (47 loc) · 1.47 KB
/
build.js
File metadata and controls
53 lines (47 loc) · 1.47 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
import { build } from 'esbuild';
import fs from 'fs';
import { nodeExternalsPlugin } from 'esbuild-node-externals'
async function runBuild() {
try {
await build({
entryPoints: ['./index.ts'], // Replace with your CLI entry point
bundle: true,
platform: 'node',
target: 'node20', // Target Node.js version
outfile: 'dist/cli.js', // Output as CommonJS
format: 'esm', // Output as ESM
minify: true,
banner: {
js: '#!/usr/bin/env node\n', // Needed for CLI executables
},
plugins: [
// Optional: exclude some dependencies from bundling
nodeExternalsPlugin({
// Bundle Polkadot packages to resolve version conflicts
allowList: ['@polkadot']
})
],
// Handle NodeJS native modules
external: ['crypto', 'fs', 'path', 'os', 'util'],
// Needed for some polkadot packages
define: {
'process.env.NODE_ENV': '"production"',
'global': 'global',
},
// Troubleshooting option
logLevel: 'info',
});
// In your build.js
// Copy the wrapper file to dist
fs.copyFileSync('cli-with-suppress.js', 'dist/cli-with-suppress.js');
// Make it executable (Unix systems)
if (process.platform !== 'win32') {
fs.chmodSync('dist/cli-with-suppress.js', '755');
}
console.log('Build completed successfully!');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
runBuild();