rsnext/packages/next/build/webpack/plugins/wellknown-errors-plugin/index.ts

32 lines
967 B
TypeScript
Raw Normal View History

import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
2020-05-13 17:43:41 +02:00
import { getModuleBuildError } from './webpackModuleError'
export class WellKnownErrorsPlugin {
apply(compiler: webpack.Compiler) {
2020-05-18 21:24:37 +02:00
compiler.hooks.compilation.tap('WellKnownErrorsPlugin', (compilation) => {
compilation.hooks.afterSeal.tapPromise(
'WellKnownErrorsPlugin',
async () => {
if (compilation.errors?.length) {
await Promise.all(
compilation.errors.map(async (err, i) => {
try {
const moduleError = await getModuleBuildError(
compilation,
err
)
if (moduleError !== false) {
compilation.errors[i] = moduleError
}
} catch (e) {
console.log(e)
}
})
)
}
2020-05-13 17:43:41 +02:00
}
)
2020-05-13 17:43:41 +02:00
})
}
}