-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.mjs
50 lines (40 loc) · 1.09 KB
/
build.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
import path from 'path';
import glob from 'fast-glob';
import { fileURLToPath } from 'url';
import ts from "typescript";
import esbuild from "esbuild";
// we need to change up how __dirname is used for ES6 purposes
const __dirname = path.dirname(fileURLToPath(import.meta.url));
async function main() {
// Absolute path to package directory
const basePath = __dirname;
const target = "es2017";
// Get all .ts as input files
const entryPoints = glob.sync(path.resolve(basePath, "src", "**.ts")
.replace(/\\/g, '/')); // windows support
const outdir = path.join(basePath, 'build');
// CommonJS output
console.log("Generating CJS build...");
esbuild.build({
entryPoints,
outdir,
format: "cjs",
target,
sourcemap: "external",
platform: "node",
});
// ESM output
console.log("Generating ESM build...");
esbuild.build({
entryPoints,
outdir,
target: "esnext",
format: "esm",
bundle: true,
sourcemap: "external",
platform: "node",
outExtension: { '.js': '.mjs', },
});
console.log("Done!");
}
export default await main();