-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
57 lines (53 loc) · 1.39 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
import path from "path";
import glob from "glob";
import svgrPlugin from "esbuild-plugin-svgr";
import esbuild from "esbuild";
import copyStaticFiles from "esbuild-copy-static-files";
// Resolve paths starting with / as relative to client/
const rootdirPlugin = function(rootdir) {
return {
name: "rootdir",
setup(build) {
build.onResolve({ filter: /^\// }, args => {
const exact = glob.sync(path.join(path.resolve(rootdir), args.path));
if (exact.length) {
return { path: exact[0] };
} else {
const match = glob.sync(path.join(path.resolve(rootdir), `${args.path}.*`));
return { path: match[0] };
}
});
},
};
};
// https://github.com/evanw/esbuild/issues/438#issuecomment-705120203
const define = {};
for (const k in process.env) {
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
}
const buildOptions = {
entryPoints: ["client/index.js"],
// absWorkingDir: `${process.cwd()}/client`,
bundle: true,
outdir: "build/",
sourcemap: true,
// splitting: true,
loader: {
".js": "jsx",
".woff2": "dataurl",
},
plugins: [
rootdirPlugin("client/"),
svgrPlugin({ ref: true }),
copyStaticFiles({
src: "client/static/",
dest: "build/",
}),
],
define,
};
if (process.argv[2] == "serve") {
esbuild.serve({port: 3031, servedir: "build"}, buildOptions);
} else {
esbuild.build(buildOptions);
}