-
Notifications
You must be signed in to change notification settings - Fork 2
/
bundle.js
50 lines (45 loc) · 1.04 KB
/
bundle.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
//@ts-check
var fs = require("fs");
var cp = require("child_process");
var esbuild = require("esbuild");
const { readdirSync } = fs;
var path = require("path");
var src = path.join(__dirname, "src");
var targets = readdirSync(src)
.filter((x) => x.endsWith(".mjs"))
.map((file) => path.join(src, file));
var plugin = {
name: "react",
setup(build) {
build.onResolve({ filter: /^(react|react-dom)$/ }, (args) => {
return {
path: args.path,
namespace: "globalExternal",
};
});
build.onLoad({ filter: /^react/, namespace: "globalExternal" }, (args) => {
var map = {
react: `React`,
"react-dom": `ReactDOM`,
};
return {
contents: `module.exports = globalThis.${map[args.path]}`,
loader: "js",
};
});
},
};
esbuild.build({
entryPoints: targets,
bundle: true,
minifySyntax: true,
sourcemap: false,
define: {
["process.env.NODE_ENV"]: "'production'",
},
outdir: "src",
outExtension: {
".js": ".bundle.js",
},
plugins: [plugin],
});