forked from keldaanCommunity/pokemonAutoChess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
49 lines (46 loc) · 1.47 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
const fs = require("fs")
const { context } = require("esbuild")
const dotenv = require("dotenv")
dotenv.config()
const isDev = process.argv[2] === "--dev"
const isProdBuild = process.argv[2] === "--build"
context({
entryPoints: ["./app/public/src/index.tsx"],
outfile: "app/public/dist/client/index.js",
external: ["assets/*"],
bundle: true,
metafile: true,
minify: isProdBuild,
sourcemap: isProdBuild,
target: "es2016",
define: {
"process.env.FIREBASE_API_KEY": `"${process.env.FIREBASE_API_KEY}"`,
"process.env.FIREBASE_AUTH_DOMAIN": `"${process.env.FIREBASE_AUTH_DOMAIN}"`,
"process.env.FIREBASE_PROJECT_ID": `"${process.env.FIREBASE_PROJECT_ID}"`,
"process.env.FIREBASE_STORAGE_BUCKET": `"${process.env.FIREBASE_STORAGE_BUCKET}"`,
"process.env.FIREBASE_MESSAGING_SENDER_ID": `"${process.env.FIREBASE_MESSAGING_SENDER_ID}"`,
"process.env.FIREBASE_APP_ID": `"${process.env.FIREBASE_APP_ID}"`
}
})
.then((context) => {
if (isDev) {
// Enable watch mode
context.watch()
} else {
// Build once and exit if not in watch mode
context.rebuild().then((result) => {
if (result.metafile) {
// use https://esbuild.github.io/analyze/ to analyse
fs.writeFileSync(
"app/public/dist/client/esbuild.meta.json",
JSON.stringify(result.metafile)
)
}
context.dispose()
})
}
})
.catch((error) => {
console.error(error)
process.exit(1)
})