-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.mjs
35 lines (33 loc) · 1.04 KB
/
build.mjs
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
import esbuild from 'esbuild'
import fs from 'node:fs/promises'
import { promisify } from 'node:util'
import { gzip as _gzip } from 'node:zlib'
const gzip = promisify(_gzip)
const gzipSize = async (filename) => (await gzip(await fs.readFile(filename))).byteLength
/** @type esbuild.BuildOptions */
const options = {
entryPoints: {
'index': 'src/index.ts',
'styles.min': 'styles.css',
'styles2.min': 'styles2.css',
},
outdir: '.',
bundle: true,
minify: true,
plugins: [{
name: 'gzip-size',
setup(build) {
build.onEnd(async () => {
const [index, styles, styles2] = await Promise.all(['index.js', 'styles.min.css', 'styles2.min.css'].map(gzipSize))
console.log(` index.js: ${index} bytes`)
console.log(` styles.min.css: ${styles} bytes`)
console.log(`styles2.min.css: ${styles2} bytes`)
})
},
}],
}
if (process.argv.includes('--serve')) {
esbuild.serve({ servedir: '.' }, options).then(({ port }) => console.log(`http://localhost:${port}`))
} else {
esbuild.build(options)
}