cc1f3b8a38
Add support for AVIF to `next/image` - Fixes #27882 - Closes #27432 ## Feature - [x] Implements an existing feature request - [x] Related issues linked - [x] Integration tests added - [x] Documentation added - [x] Update manifest output - [x] Warn when `sharp` is outdated - [x] Errors & Warnings have helpful link attached - [ ] Remove `image-size` in favor of `squoosh`/`sharp` (optional, need to benchmark)
30 lines
820 B
TypeScript
30 lines
820 B
TypeScript
import curry from 'next/dist/compiled/lodash.curry'
|
|
import { webpack } from 'next/dist/compiled/webpack/webpack'
|
|
import { loader } from '../../helpers'
|
|
import { ConfigurationContext, ConfigurationFn, pipe } from '../../utils'
|
|
import { getCustomDocumentImageError } from './messages'
|
|
|
|
export const images = curry(async function images(
|
|
_ctx: ConfigurationContext,
|
|
config: webpack.Configuration
|
|
) {
|
|
const fns: ConfigurationFn[] = [
|
|
loader({
|
|
oneOf: [
|
|
{
|
|
test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,
|
|
use: {
|
|
loader: 'error-loader',
|
|
options: {
|
|
reason: getCustomDocumentImageError(),
|
|
},
|
|
},
|
|
issuer: /pages[\\/]_document\./,
|
|
},
|
|
],
|
|
}),
|
|
]
|
|
|
|
const fn = pipe(...fns)
|
|
return fn(config)
|
|
})
|