Skip to content

Commit 9d25498

Browse files
committed
feat: timePlugin
1 parent 4ff82cb commit 9d25498

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

build.config.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
import { defineConfig } from './src/config.ts'
22

3+
function timePlugin() {
4+
let startTime: bigint | undefined
5+
6+
const formatDuration = (ns: bigint) => {
7+
const ms = Number(ns) / 1e6
8+
if (ms < 1000) {
9+
return `${ms.toFixed(2)} ms`
10+
}
11+
12+
return `${(ms / 1000).toFixed(2)} s`
13+
}
14+
15+
return {
16+
name: 'robuild-plugin-build',
17+
buildStart() {
18+
startTime = process.hrtime.bigint()
19+
console.log('buildStart...')
20+
},
21+
async buildEnd() {
22+
const end = process.hrtime.bigint()
23+
if (startTime) {
24+
const diff = end - startTime
25+
console.log(`buildEnd... elapsed: ${formatDuration(diff)}`)
26+
}
27+
else {
28+
console.log('buildEnd...')
29+
}
30+
},
31+
}
32+
}
33+
334
export default defineConfig({
435
entries: [
536
{
@@ -17,17 +48,6 @@ export default defineConfig({
1748
watchNewFiles: true,
1849
},
1950
plugins: [
20-
{
21-
name: 'robuild-plugin-build',
22-
transform(code, id) {
23-
console.log({ id })
24-
return {
25-
code,
26-
}
27-
},
28-
async buildEnd() {
29-
console.log('✅ buildEnd...')
30-
},
31-
},
51+
timePlugin(),
3252
],
3353
})

0 commit comments

Comments
 (0)