first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
@@ -0,0 +1,4 @@
const UniAppErrorsWebpackPlugin = require('./webpack-errors-plugin')
module.exports = UniAppErrorsWebpackPlugin
@@ -0,0 +1,18 @@
/**
* Dedupes array based on criterion returned from iteratee function.
* Ex: uniqueBy(
* [{ id: 1 }, { id: 1 }, { id: 2 }],
* val => val.id
* ) = [{ id: 1 }, { id: 2 }]
*/
function uniqueBy (arr, fun) {
const seen = {}
return arr.filter(el => {
const e = fun(el)
return !(e in seen) && (seen[e] = 1)
})
}
module.exports = {
uniqueBy: uniqueBy
}
@@ -0,0 +1,54 @@
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