-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
53 lines (47 loc) · 1.39 KB
/
build.ts
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
import {sassPlugin} from 'esbuild-sass-plugin'
import {build, BuildOptions, context} from "esbuild";
import * as fs from "fs";
const commonOption: BuildOptions = {
entryPoints: ['assets/main.ts', 'assets/redirector.ts', "assets/scss/main.scss", 'assets/katex.css'],
target: "esnext",
format: "esm",
bundle: true,
sourcemap: true,
minify: true,
outdir: "public/assets",
splitting: true,
// @ts-ignore https://github.com/glromeo/esbuild-sass-plugin/issues/109
plugins: [sassPlugin()],
loader: {
".ttf": "file",
".woff": "file",
".woff2": "file",
".svg": "text",
".png": "base64"
},
entryNames: "[name]"
}
switch (process.argv[2]) {
case "build":
commonOption.metafile = true
commonOption.entryNames = "[name]-[hash]"
build(commonOption).then(result => {
fs.writeFileSync(commonOption.outdir + "/meta.json", JSON.stringify(result.metafile))
})
break
case "serve":
commonOption.minify = false
commonOption
context(commonOption).then(ctx => {
ctx.serve({
port: 1234,
servedir: "public"
}).catch((e) => {
console.error(e)
process.exit(1)
}).then(data => console.log(data))
})
break
default:
console.log(process.argv)
}