mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-09-26 22:49:14 +08:00
39 lines
812 B
TypeScript
39 lines
812 B
TypeScript
import { Stats } from 'webpack'
|
|
|
|
export const defaultWatcherHandler = (
|
|
initCallback: (result: Stats) => void,
|
|
updateCallback: (result: Stats) => void,
|
|
) => {
|
|
let lastHash = ''
|
|
return (error: Error, result: Stats) => {
|
|
if (error) {
|
|
console.error(error)
|
|
return
|
|
}
|
|
if (result.hash === lastHash) {
|
|
return
|
|
}
|
|
const needLogging = result.hasErrors() || result.hasWarnings()
|
|
if (needLogging) {
|
|
console.log(
|
|
result.toString({
|
|
hash: false,
|
|
assets: false,
|
|
modules: false,
|
|
chunks: false,
|
|
colors: true,
|
|
}),
|
|
)
|
|
}
|
|
if (result.hasErrors()) {
|
|
lastHash = ''
|
|
return
|
|
}
|
|
if (!lastHash) {
|
|
initCallback(result)
|
|
}
|
|
lastHash = result.hash
|
|
updateCallback(result)
|
|
}
|
|
}
|