Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ module.exports = function (webpackEnv) {
// smaller than specified limit in bytes as data URLs to avoid requests.
// A missing `test` is equivalent to a match.
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
test: [/\.avif$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this didn't work correctly 😢

image/avif appears to be missing from mime-db which is used by this loader. This means that when the image is inlined, it doesn't know the correct mime type to use in the data URI, and breaks the image:

image

As a temporary fix until the mime type is available, i've updated the webpack config to define loader config specifically for .avif files so that we can hardcode the mime type. This worked well in my testing.

loader: require.resolve('url-loader'),
options: {
limit: imageInlineSizeLimit,
Expand Down
5 changes: 5 additions & 0 deletions packages/react-scripts/lib/react-app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ declare namespace NodeJS {
}
}

declare module '*.avif' {
const src: string;
export default src;
}

declare module '*.bmp' {
const src: string;
export default src;
Expand Down