-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbuild.js
63 lines (55 loc) · 1.48 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable */
const { build } = require("esbuild");
const { nodeExternalsPlugin } = require("esbuild-node-externals");
const pkg = require(`${process.cwd()}/package.json`);
const isIsomorphicBuild = ["@hyper-fetch/core", "@hyper-fetch/graphql"].includes(pkg.name);
const isNodeOnly = ["@hyper-fetch/codegen-openapi"].includes(pkg.name);
/**
* Building
*/
const buildPackage = async (additionalOptions = {}) => {
const {
platform = "browser",
outputMain = pkg.main,
outputModule = pkg.module,
tsconfig = "tsconfig.json",
preDir = "",
} = additionalOptions;
const options = {
platform,
target: "es6",
entryPoints: [pkg.source],
bundle: true,
minify: false,
sourcemap: true,
treeShaking: true,
tsconfig,
plugins: [nodeExternalsPlugin()],
};
build({
...options,
outfile: preDir ? outputMain.replace("dist", preDir) : outputMain,
format: "cjs",
});
build({
...options,
outfile: preDir ? outputModule.replace("dist", preDir) : outputModule,
format: "esm",
});
if (pkg.cli) {
build({
...options,
entryPoints: [pkg.cli],
outfile: pkg.climain,
format: "cjs",
});
}
};
if (isIsomorphicBuild) {
buildPackage({ platform: "browser", preDir: "dist/browser", tsconfig: "tsconfig.base.json" });
buildPackage({ platform: "node", tsconfig: "tsconfig.json" });
} else if (isNodeOnly) {
buildPackage({ platform: "node", tsconfig: "tsconfig.json" });
} else {
buildPackage();
}