rsnext/packages/next/build/webpack/loaders/error-loader.ts
Guy Bedford 005a8abe39
feat: Webpack loader inlining (#21127)
This picks up on the inlining work in https://github.com/vercel/next.js/pull/20598 to also include webpack loader inlining optimizations.

This includes:
* The dependencies of sass-loader
* resolve-url-loader

And for added benefit:
* babel-plugin-transform-define
* babel-plugin-transform-react-remove-prop-types

style-loader and css-loader didn't inline easily. Perhaps we can come back to these ones.
2021-01-15 01:51:45 +00:00

26 lines
722 B
TypeScript

import chalk from 'chalk'
import loaderUtils from 'next/dist/compiled/loader-utils'
import path from 'path'
import { webpack } from 'next/dist/compiled/webpack/webpack'
const ErrorLoader: webpack.loader.Loader = function () {
const options = loaderUtils.getOptions(this) || {}
const { reason = 'An unknown error has occurred' } = options
const resource = this._module?.issuer?.resource ?? null
const context = this.rootContext ?? this._compiler?.context
const issuer = resource
? context
? path.relative(context, resource)
: resource
: null
const err = new Error(
reason + (issuer ? `\nLocation: ${chalk.cyan(issuer)}` : '')
)
this.emitError(err)
}
export default ErrorLoader