-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
54 lines (48 loc) · 1.41 KB
/
esbuild.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
const esbuild = require('esbuild');
const glob = require('glob');
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
const stdLibBrowser = require('node-stdlib-browser');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
/*
The reason why we use esbuild instead of tsc is because esbuild can output .mjs files
*/
const filesToInclude = ['./src/**/*.ts'].join(',');
const allFiles = glob.sync(filesToInclude);
const files = allFiles.filter((file) => {
const hasTestFiles = file.includes('/tests/') || file.includes('/stories/');
return !hasTestFiles;
});
const executeBuild = () =>
esbuild
.build({
entryPoints: files,
splitting: true,
format: 'esm',
outdir: 'out',
treeShaking: true,
minify: true,
bundle: true,
sourcemap: true,
chunkNames: '__chunks__/[name]-[hash]',
target: ['es2021'],
outExtension: { '.js': '.mjs' },
tsconfig: './tsconfig.json',
platform: 'node',
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer'
},
plugins: [plugin(stdLibBrowser), nodeExternalsPlugin()]
})
.then(() => {
console.log(
'\x1b[36m%s\x1b[0m',
`[${new Date().toLocaleTimeString()}] sdk-dapp-core build succeeded for esm types`
);
})
.catch((err) => {
console.log(11, err);
process.exit(1);
});
executeBuild();