-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
40 lines (37 loc) · 1.01 KB
/
build.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
import path from "path";
import { fileURLToPath } from "url";
import { build } from "esbuild";
// import { createRequire } from 'module';
// const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
try {
// Bundle the front-end code which will be imported by
// the worker code as text.
await build({
bundle: true,
format: "iife",
entryPoints: [path.join(__dirname, 'src', "client.js")],
outfile: path.join(__dirname, 'dist', 'client.js.gen'),
logLevel: 'info',
});
// Bundle up the Cloudflare worker module.
await build({
bundle: true,
sourcemap: 'inline',
format: "esm",
target: "esnext",
entryPoints: [path.join(__dirname, "src", "worker.ts")],
outdir: path.join(__dirname, "dist"),
outExtension: { ".js": ".mjs" },
plugins: [],
loader: {
'.html': 'text',
'.gen': 'text',
},
logLevel: 'info',
});
} catch (e) {
console.error(e);
process.exitCode = 1;
}