-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-cli.js
48 lines (46 loc) · 1.08 KB
/
build-cli.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
import * as esbuild from "esbuild";
import path from "node:path";
import { readFile } from "node:fs/promises";
/**
* @type import("esbuild").Plugin
*/
const ImportRawPlugin = {
name: "raw",
setup: (build) => {
build.onResolve({ filter: /\?raw$/ }, (args) => {
return {
path: args.path,
pluginData: {
isAbsolute: path.isAbsolute(args.path),
resolveDir: args.resolveDir,
},
namespace: "raw-loader",
};
});
build.onLoad(
{ filter: /\?raw$/, namespace: "raw-loader" },
async (args) => {
const fullPath = args.pluginData.isAbsolute
? args.path
: path.join(args.pluginData.resolveDir, args.path);
return {
contents: await readFile(fullPath.replace(/\?raw$/, "")),
loader: "text",
};
},
);
},
};
await esbuild.build({
entryPoints: ["src/cli/cli.ts"],
bundle: true,
outdir: "build",
format: "esm",
platform: "node",
loader: {
".java": "text",
},
packages: "external",
sourcemap: true,
plugins: [ImportRawPlugin],
});