-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.js
60 lines (53 loc) · 1.45 KB
/
esbuild.config.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
import * as path from "path";
import esbuild from "esbuild";
import { globby } from "globby";
const watchMode = process.argv.includes("--watch");
const cdndir = path.join(process.cwd(), "cdn", "exports");
const bundleDir = path.join(process.cwd(), "bundles");
(async () => {
const entryPoints = await globby("./exports/**/*.js");
/**
* @type {import("esbuild").BuildOptions}
*/
const coreConfig = {
format: "esm",
target: "es2017",
chunkNames: "chunks/[name].[hash]",
define: {
// Floating UI requires this to be set
"process.env.NODE_ENV": '"production"',
},
external: [],
bundle: true,
};
/**
* @type {import("esbuild").BuildOptions}
*/
const cdnConfig = {
...coreConfig,
entryPoints,
splitting: true,
treeShaking: true,
outdir: cdndir,
};
/**
* @type {import("esbuild").BuildOptions}
*/
const allConfig = {
...coreConfig,
entryPoints: ["./exports/index.js"],
outfile: path.join(bundleDir, "all.js"),
};
const configs = [cdnConfig, allConfig];
if (watchMode) {
// Use the context API to allow incremental dev builds
const contexts = await Promise.all(
configs.map((config) => esbuild.context(config)),
);
await Promise.all(contexts.map((context) => context.rebuild()));
return contexts;
} else {
// Use the standard API for production builds
return await Promise.all(configs.map((config) => esbuild.build(config)));
}
})();