-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
48 lines (44 loc) · 1.41 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
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import * as fs from "fs";
import * as dotenv from "dotenv";
import path from "path";
import esbuild from "esbuild";
import { fileURLToPath } from "url";
import { argv } from "process";
const dir = path.dirname(fileURLToPath(import.meta.url)).replace(/\\/g, "/");
const arg = argv.length > 2 ? argv[2] : undefined;
const dotEnvPath = path.resolve(process.cwd(), ".env");
if (fs.existsSync(dotEnvPath)) {
const result = dotenv.config();
if (result.error)
throw result.error;
}
const envVars = JSON.stringify({
CLIENT_ID: process.env.CLIENT_ID,
SCOPES: process.env.SCOPES,
ITWIN_ID: process.env.ITWIN_ID,
IMODEL_ID: process.env.IMODEL_ID,
BING_KEY: process.env.BING_KEY,
});
esbuild
.build({
format: "esm",
entryPoints: ["src/index.ts"],
watch: arg === "--watch" ? true : false,
bundle: true,
minify: true,
sourcemap: true,
define: { global: "window", __dirname: `"${dir}"`, ENV: envVars },
outfile: "public/dist/bundle.js",
plugins: [new NodeGlobalsPolyfillPlugin(), new NodeModulesPolyfillPlugin()],
loader: {
".svg": "dataurl",
".woff": "dataurl",
".eot": "dataurl",
".ttf": "dataurl",
".woff2": "dataurl",
".cur": "dataurl",
},
})
.catch(() => process.exit(1));