forked from hpcc-systems/Visualization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
90 lines (80 loc) · 3.69 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const { build } = require("esbuild");
const path = require("path");
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function resolver(options) {
const aliases = Object.keys(options);
const re = new RegExp(`^(${aliases.map(x => escapeRegExp(x)).join("|")})$`);
return {
name: "resolver",
setup(build) {
build.onResolve({ filter: /^@hpcc-js\/wc-/ }, args => {
const package = args.path.replace("@hpcc-js/wc-", "");
const aliasPath = path.join(__dirname, "components", package, "/src/index.ts");
return {
path: aliasPath
};
});
build.onResolve({ filter: /^@hpcc-js\// }, args => {
const package = args.path.replace("@hpcc-js/", "");
const aliasPath = path.join(__dirname, "packages", package, "/src/index.ts");
return {
path: aliasPath
};
});
build.onResolve({ filter: re }, args => {
return {
path: options[args.path],
};
});
},
};
}
function doBuild(input, output, format) {
build({
entryPoints: [input],
outfile: output,
target: "es2019",
bundle: true,
format: format ? format : "esm",
minify: true,
sourcemap: true,
plugins: [
resolver({
"react": require.resolve("preact/compat"),
"react-dom/test-utils": require.resolve("preact/test-utils"),
"react-dom": require.resolve("preact/compat"),
"react/jsx-runtime": require.resolve("preact/jsx-runtime"),
}),
]
}).catch((err) => {
console.error(err);
process.exit(1);
});
}
// Vitepress hosted components ---
doBuild("src/index.ts", ".vitepress/dist/assets/index.js");
// Preview hosted components ---
doBuild("components/editor/src/index.ts", ".vitepress/dist/assets/wc-editor.js");
doBuild("components/layout/src/index.ts", ".vitepress/dist/assets/wc-layout.js");
doBuild("components/observable/src/index.ts", ".vitepress/dist/assets/wc-observable.js");
doBuild("components/preview/src/index.ts", ".vitepress/dist/assets/wc-preview.js");
doBuild("packages/chart/src/index.ts", ".vitepress/dist/assets/chart.js");
doBuild("packages/dgrid2/src/index.ts", ".vitepress/dist/assets/dgrid2.js");
doBuild("packages/observablehq-compiler/src/index.ts", ".vitepress/dist/assets/observablehq-compiler.js");
doBuild("packages/observable-md/src/index.ts", ".vitepress/dist/assets/observable-md.js");
// doBuild("components/core/src/index.ts", ".vitepress/dist/assets/wc-core.js");
// doBuild("packages/codemirror/src/index.ts", ".vitepress/dist/assets/codemirror.js");
// doBuild("packages/dgrid/src/index.ts", ".vitepress/dist/assets/dgrid.js");
// doBuild("packages/dgrid2/src/index.ts", ".vitepress/dist/assets/dgrid2.js");
// doBuild("packages/graph/src/index.ts", ".vitepress/dist/assets/graph.js");
// doBuild("packages/layout/src/index.ts", ".vitepress/dist/assets/layout.js");
// doBuild("packages/map/src/index.ts", ".vitepress/dist/assets/map.js");
// doBuild("packages/map-deck/src/index.ts", ".vitepress/dist/assets/map-deck.js");
// doBuild("packages/observable-md/src/index.ts", ".vitepress/dist/assets/observable-md.js");
// doBuild("packages/react/src/index.ts", ".vitepress/dist/assets/react.js");
// doBuild("packages/timeline/src/index.ts", ".vitepress/dist/assets/timeline.js");
// doBuild("packages/tree/src/index.ts", ".vitepress/dist/assets/tree.js");