diff --git a/lib/builder/webpack/plugins/progress.js b/lib/builder/webpack/plugins/progress.js index f72e8a045f..646341447b 100644 --- a/lib/builder/webpack/plugins/progress.js +++ b/lib/builder/webpack/plugins/progress.js @@ -30,15 +30,19 @@ module.exports = function ProgressPlugin({ color, pcolor, title }) { let consoleSpied = false +const silentConsole = {} +const originalConsole = {} const consoleQueue = { log: [], + warn: [], error: [] } -const silentConsole = { - log: (...args) => consoleQueue.log.push(args), - error: (...args) => consoleQueue.error.push(args) -} +// level: log, warn, error +Object.keys(consoleQueue).forEach((level) => { + silentConsole[level] = (...args) => consoleQueue[level].push(args) + originalConsole[level] = console[level] // eslint-disable-line no-console +}) const muteConsole = () => { if (consoleSpied) return @@ -47,22 +51,15 @@ const muteConsole = () => { Object.assign(console, silentConsole) } -const originalConsole = { - log: console.log, // eslint-disable-line no-console - error: console.error // eslint-disable-line no-console -} - const restoreConsole = () => { if (!consoleSpied) return consoleSpied = false Object.assign(console, originalConsole) - const l = consoleQueue.log - consoleQueue.log = [] - l.forEach(args => console.log(...args)) // eslint-disable-line no-console - - const e = consoleQueue.error - consoleQueue.error = [] - e.forEach(args => console.error(...args)) // eslint-disable-line no-console + // level: log, warn, error + for (let level in consoleQueue) { + consoleQueue[level].forEach(args => console[level](...args)) // eslint-disable-line no-console + consoleQueue[level] = [] + } }