Skip to content

Commit

Permalink
feat(core): print filesizes on build
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jul 4, 2020
1 parent 5336985 commit 63e2c2c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/core/src/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dirname } from 'path'
import { dirname, join } from 'path'

import { bold, gray } from 'chalk'
import { remove } from 'fs-extra'
import { bold, gray, green } from 'chalk'
import { remove, stat } from 'fs-extra'
import { rollup, watch, RollupError } from 'rollup'

import type { BuildOptions, Package } from '../package'
Expand Down Expand Up @@ -116,9 +116,26 @@ export const build = async (
}

const { output } = await bundle.write(outputConfig)

const { fileName } = output[0]
let size
try {
const filePath = outputConfig.dir
? join(outputConfig.dir, fileName)
: outputConfig.file || fileName
const { size: bytes } = await stat(filePath)
if (bytes > 500) {
size = green(
' ' + bold((bytes / 1024).toFixed(1).padStart(5)) + ' kB'
)
} else {
size = green(' ' + bold(String(bytes).padStart(5)) + ' B')
}
// eslint-disable-next-line
} catch {}
pkg.logger.success(
`Built ${bold(pkg.pkg.name)} ${gray(output[0].fileName)}`
`Built ${bold(pkg.pkg.name.padEnd(15))} ${gray(
fileName.padStart(15)
)}${size}`
)
})
await pkg.callHook('build:done', { bundle })
Expand Down

0 comments on commit 63e2c2c

Please sign in to comment.