Skip to content

Commit

Permalink
feat: support avif file resolve (umijs#7273)
Browse files Browse the repository at this point in the history
Co-authored-by: 张倬辉 <[email protected]>
  • Loading branch information
zoffyzhang and 张倬辉 authored Sep 6, 2021
1 parent 7f8abd5 commit badc5c7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/bundler-webpack/src/fixtures/avif/expect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IExpectOpts } from '../types';

export default ({ indexJS }: IExpectOpts) => {
expect(indexJS).toContain(`__webpack_require__.p + "static/mustache.`);
};
4 changes: 4 additions & 0 deletions packages/bundler-webpack/src/fixtures/avif/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from 'react'
import img from './mustache.avif';

export default () => <img src={img} alt="mustache.avif" />
Binary file not shown.
11 changes: 11 additions & 0 deletions packages/bundler-webpack/src/getConfig/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ export default async function getConfig(
}
});

// prettier-ignore
webpackConfig.module
.rule('avif')
.test(/\.(avif)(\?.*)?$/)
.use('file-loader')
.loader(require.resolve('@umijs/deps/compiled/file-loader'))
.options({
name: `${staticDir}/[name].[hash:8].[ext]`,
esModule: false,
});

// prettier-ignore
webpackConfig.module
.rule('svg')
Expand Down
1 change: 1 addition & 0 deletions types/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ interface Window {
declare module '@umijs/bundler-webpack/lib/requireHook';

declare module '*.less';
declare module '*.avif';

0 comments on commit badc5c7

Please sign in to comment.