智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LightingSystemApp-serial/.svn/pristine/b6/b670db4dc03d71222a266d84a45...

55 lines
1.3 KiB

3 years ago
const utils = require('./utils')
const uniqueBy = utils.uniqueBy
class WebpackErrorsPlugin {
constructor (options) {
options = options || {}
this.sourceRoot = options.sourceRoot
this.onErrors = options.onErrors
this.onWarnings = options.onWarnings
}
apply (compiler) {
const doneFn = stats => {
const hasErrors = stats.hasErrors()
const hasWarnings = stats.hasWarnings()
if (hasErrors && this.onErrors) {
this.onErrors(extractErrorsFromStats(stats, 'errors'))
return
}
if (hasWarnings && this.onWarnings) {
this.onWarnings(extractErrorsFromStats(stats, 'warnings'))
}
}
if (compiler.hooks) {
const plugin = {
name: 'UniAppErrorsWebpackPlugin'
}
compiler.hooks.done.tap(plugin, doneFn)
} else {
compiler.plugin('done', doneFn)
}
}
}
function extractErrorsFromStats (stats, type) {
if (isMultiStats(stats)) {
const errors = stats.stats
.reduce((errors, stats) => errors.concat(extractErrorsFromStats(stats, type)), [])
// Dedupe to avoid showing the same error many times when multiple
// compilers depend on the same module.
return uniqueBy(errors, error => error.message)
}
return stats.compilation[type]
}
function isMultiStats (stats) {
return stats.stats
}
module.exports = WebpackErrorsPlugin