mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-25 15:07:17 +02:00
feat(webpack): add better log output
This commit is contained in:
parent
0bbe7fd999
commit
56dfec19ea
2 changed files with 49 additions and 18 deletions
29
lib/webpack/plugin/log.js
Normal file
29
lib/webpack/plugin/log.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
const chalk = require('chalk');
|
||||
const ora = require('ora');
|
||||
module.exports = class LogPlugin {
|
||||
constructor (options) {
|
||||
this.options = options
|
||||
}
|
||||
|
||||
apply (compiler) {
|
||||
const logger = ora();
|
||||
let isFirst = true
|
||||
compiler.hooks.done.tap('blogi-log', stats => {
|
||||
clearScreen()
|
||||
|
||||
const { port, publicPath } = this.options
|
||||
const time = new Date().toTimeString().match(/^[\d:]+/)[0]
|
||||
|
||||
logger.succeed(`${chalk.gray(`[${time}]`)} Build ${chalk.yellow(stats.hash.slice(0, 6))} finished in ${chalk.green(stats.endTime - stats.startTime)} ms!`)
|
||||
if (isFirst) {
|
||||
isFirst = false
|
||||
console.log(`\n${chalk.gray('>')} Blogi dev server listening at ${chalk.cyan(`http://localhost:${port}${publicPath}`)}`)
|
||||
}
|
||||
})
|
||||
compiler.hooks.invalid.tap('blogi-log', clearScreen)
|
||||
}
|
||||
}
|
||||
|
||||
function clearScreen () {
|
||||
process.stdout.write('\x1Bc')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue