-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
40 lines (34 loc) · 1.14 KB
/
build.js
File metadata and controls
40 lines (34 loc) · 1.14 KB
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
import { build } from 'esbuild'
import { readdir, stat } from 'fs/promises'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const entryFiles = (await readdir(path.join(__dirname, 'src')))
.filter(file => file.endsWith('.js'))
for (const file of entryFiles) {
const entry = path.join('src', file)
const baseName = path.basename(file, '.js')
const outPath = path.join('dist', `${baseName}.min.js`)
const sourcemapPath = path.join('dist', `${baseName}.min.js.map`)
await build({
entryPoints: [entry],
outfile: outPath,
alias: {
'#': path.resolve(__dirname, 'src'),
'#libs': path.resolve(__dirname, 'libs'),
},
minify: true,
bundle: true,
sourcemap: true
})
const stats = await stat(outPath)
const sizeKB = (stats.size / 1024).toFixed(2)
console.log(`✔ ${outPath} (${sizeKB} KB)`)
try {
const sourcemapStats = await stat(sourcemapPath)
const sourcemapSizeKB = (sourcemapStats.size / 1024).toFixed(2)
console.log(`✔ ${sourcemapPath} (${sourcemapSizeKB} KB)`)
} catch(_) {
}
}