-
Notifications
You must be signed in to change notification settings - Fork 8
/
esbuild.config.mts
62 lines (56 loc) · 1.5 KB
/
esbuild.config.mts
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
import { readFile } from 'node:fs/promises';
import assert from 'node:assert/strict';
import esbuild, { BuildOptions, Plugin } from 'esbuild';
import {
combineConfigs,
configBase,
configBundleWithoutNodeModules,
configTargetSpecific,
} from '../esbuild.common.mjs';
async function buildAutoankiBridge(): Promise<string> {
const result = esbuild.buildSync({
entryPoints: ['src/bridge/index.ts'],
outfile: 'dist/bridge.js',
...configTargetSpecific.ankiWebViewScript,
});
assert(result.errors.length === 0);
const content = await readFile('dist/bridge.js');
return content.toString();
}
export const pluginBundleAutoankiBridgeAsBase64 = {
name: 'bundle_autoanki_bridge',
setup(build) {
build.onResolve({ filter: /bridge\/index\.bundled\.js$/ }, (args) => {
return {
path: args.path,
namespace: 'bridge',
};
});
build.onLoad(
{ filter: /bridge\/index\.bundled\.js$/, namespace: 'bridge' },
async (args) => {
return {
contents: await buildAutoankiBridge(),
loader: 'base64',
};
}
);
},
};
const config: BuildOptions = {
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
plugins: [pluginBundleAutoankiBridgeAsBase64],
// bundle css of transfomer plugin as base64
loader: { '.css': 'base64' },
};
esbuild
.build(
combineConfigs(
configBase,
configBundleWithoutNodeModules(),
configTargetSpecific.esmLib,
config
)
)
.catch(() => process.exit(1));