-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
58 lines (49 loc) · 1.36 KB
/
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
49
50
51
52
53
54
55
56
57
58
import esbuild from "esbuild"
import fs from "node:fs"
import { gzipSizeFromFileSync } from "gzip-size"
const files = {
"src/_web": "all",
"src/math/_web": "math",
"src/camera/_web": "camera",
"src/vector/_web": "vector",
"src/collision/_web": "collision",
"src/grid/_web": "grid",
"src/actor/_web": "actor",
"src/tween/_web": "tween",
"src/noise/_web": "noise",
"src/image/_web": "image",
"src/collection/_web": "collection",
},
outdir = "dist"
fs.rmSync(outdir, { recursive: true, force: true })
for (let [path, name] of Object.entries(files)) {
let outfile = `${outdir}/${name}.js`
await esbuild.build({
entryPoints: [`${path}.js`],
outfile,
bundle: true,
})
console.log(
` ${outfile} (${filesize(outfile)} ~= ${gzipsize(outfile)} gzipped)`
)
outfile = `${outdir}/${name}.min.js`
await esbuild.build({
entryPoints: [`${path}.js`],
outfile,
bundle: true,
minify: true,
dropLabels: ["DEV"],
})
console.log(
` ${outfile} (${filesize(outfile)} ~= ${gzipsize(outfile)} gzipped)`
)
}
function filesize(filename) {
var stats = fs.statSync(filename)
var fileSizeInBytes = stats.size
return (fileSizeInBytes / 1000).toFixed(2) + "kb"
}
function gzipsize(filename) {
const fileSizeInBytes = gzipSizeFromFileSync(filename)
return (fileSizeInBytes / 1000).toFixed(2) + "kb"
}