-
Notifications
You must be signed in to change notification settings - Fork 12
/
esbuild.config.mjs
69 lines (64 loc) · 1.75 KB
/
esbuild.config.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
import esbuild from 'esbuild';
import fs from 'fs';
import path from 'path';
import { NodeResolvePlugin } from '@esbuild-plugins/node-resolve';
import { getWasmJSContent, bufferShim } from './esbuild.base.mjs';
const wasmPlugin = {
name: 'wasm',
setup(build) {
build.onResolve({ filter: /\.wasm$/ }, args => {
if (fs.existsSync(path.resolve("externals/generated", args.path))) {
return { path: path.resolve("externals/generated", args.path), namespace: 'wasm' };
}
return { path: path.resolve(args.resolveDir, args.path), namespace: 'wasm' };
});
build.onLoad({ filter: /.*/, namespace: 'wasm' }, (args) => (
{
contents: getWasmJSContent(args.path),
loader: 'js',
}
));
},
};
const plugins = [
wasmPlugin,
NodeResolvePlugin({
extensions: ['.ts', '.js', '.wasm'],
onResolved: (resolved) => {
if (resolved.includes('node_modules')) {
return {
external: true,
}
}
return resolved
},
}),
]
const generic = {
chunkNames: "[name]",
assetNames: "[name]",
entryPoints: ['src/index.ts'],
sourcemap: false,
bundle: true,
platform: 'neutral',
splitting: false,
resolveExtensions: ['.ts', '.js', '.wasm'],
mainFields: ['module', 'main'],
target: ['esnext'],
define: {
'global.Buffer': 'Buffer',
},
banner: {
js: bufferShim,
},
external: ['buffer']
};
(async () => {
await esbuild.build({
...generic,
outdir: "build",
inject: ['anoncreds-wasm', 'didcomm-wasm', 'jwe-wasm'],
format: 'cjs',
plugins
})
})()