-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
54 lines (49 loc) · 1.2 KB
/
esbuild.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
49
50
51
52
53
54
const esbuild = require("esbuild");
const path = require("path");
const pkg = require(path.join(path.resolve("./"), `package.json`));
// bundle, but set dependencies as external
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const banner = {
js: `/**
* @name ${pkg.name}
* @fileoverview ${pkg.description}
* @version ${pkg.version}
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/${pkg.name}/}
*/
`,
};
// ESM
esbuild.buildSync({
entryPoints: [path.join(path.resolve("./"), "src/main.ts")],
platform: "node",
format: "esm",
bundle: true,
define: { DEV: !!process.env.DEV },
minify: !process.env.DEV,
sourcemap: false,
target: ["esnext"],
outfile: path.join(path.resolve("./"), `dist/${pkg.name}.esm.js`),
// pure,
banner,
external,
});
// CJS
esbuild.buildSync({
entryPoints: [path.join(path.resolve("./"), "src/main.ts")],
platform: "node",
format: "cjs",
bundle: true,
define: { DEV: !!process.env.DEV },
minify: !process.env.DEV,
sourcemap: false,
target: ["esnext"],
outfile: path.join(path.resolve("./"), `dist/${pkg.name}.cjs.js`),
// pure,
banner,
external,
});