-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.build.js
48 lines (46 loc) · 1.47 KB
/
esbuild.build.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 esbuild from "esbuild"
import postCssPlugin from "esbuild-style-plugin"
import tailwindcss from "tailwindcss"
const main = async () => {
// if no arguments are given, output help and exit
if (process.argv.length < 3) {
console.log("ERROR: you need to specify a command to execute")
console.log("esbuild.js [--build|--watch]")
console.log(" --build : builds static files for deployment")
console.log(" --serve : starts the development server. listens on port 8000")
return
}
const args = process.argv.slice(2)
// should build app and exit?
const build = args.includes("--build")
// should serve development server?
const serve = args.includes("--serve")
const ctx = await esbuild
.context({
entryPoints: ["src/App.jsx", "src/styles/app.css"],
outdir: "public/assets",
bundle: true,
minify: build, // if building static files, minify them
plugins: [
postCssPlugin({
postcss: {
plugins: [tailwindcss]
}
})
],
define: {
"window.IS_PRODUCTION": build ? "true" : "false"
}
})
if (serve) {
await ctx.watch()
const { host, port } = await ctx.serve({ servedir: "public" })
console.log(`Running development server at ${host}:${port}`)
} else {
process.stdout.write("Building static files ... ")
await ctx.rebuild()
await ctx.dispose()
console.log("done!")
}
}
main()