Skip to content

Commit

Permalink
Add support for avif images (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderShushunov committed Nov 16, 2022
1 parent 1d53f26 commit 691a4e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-crews-pull.md
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Add support for avif images format
9 changes: 3 additions & 6 deletions packages/cli/lib/commands/create.js
Expand Up @@ -31,7 +31,8 @@ const { addScripts, install, initGit } = require('../lib/setup');
const { validateArgs } = require('./validate-args');

const ORG = 'preactjs-templates';
const RGX = /\.(woff2?|ttf|eot|jpe?g|ico|png|gif|webp|mp4|mov|ogg|webm)(\?.*)?$/i;
const RGX =
/\.(woff2?|ttf|eot|jpe?g|ico|png|gif|webp|avif|mp4|mov|ogg|webm)(\?.*)?$/i;
const isMedia = str => RGX.test(str);
const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1);

Expand Down Expand Up @@ -176,11 +177,7 @@ async function fetchTemplates() {
// If cache file doesn't exist, then hit the API and fetch the data
if (!existsSync(cacheFilePath)) {
const repos = await fetch(TEMPLATES_REPO_URL).then(r => r.json());
await writeFile(
cacheFilePath,
JSON.stringify(repos, null, 2),
'utf-8'
);
await writeFile(cacheFilePath, JSON.stringify(repos, null, 2), 'utf-8');
}

// update the cache file without blocking the rest of the tasks.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/lib/webpack/webpack-base-config.js
Expand Up @@ -296,7 +296,7 @@ module.exports = function createBaseConfig(env) {
loader: require.resolve('raw-loader'),
},
{
test: /\.(svg|woff2?|ttf|eot|jpe?g|png|webp|gif|mp4|mov|ogg|webm)(\?.*)?$/i,
test: /\.(svg|woff2?|ttf|eot|jpe?g|png|webp|avif|gif|mp4|mov|ogg|webm)(\?.*)?$/i,
loader: isProd
? require.resolve('file-loader')
: require.resolve('url-loader'),
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Expand Up @@ -59,7 +59,7 @@ async function clientConfig(env) {
/200\.html$/,
/\.esm.js$/,
/\.css$/,
/\.(png|jpg|svg|gif|webp)$/,
/\.(png|jpg|svg|gif|webp|avif)$/,
],
webpackCompilationPlugins: [
new webpack.DefinePlugin({
Expand All @@ -73,7 +73,12 @@ async function clientConfig(env) {
swInjectManifest.push(
new InjectManifest({
swSrc: swPath,
include: [/200\.html$/, /\.js$/, /\.css$/, /\.(png|jpg|svg|gif|webp)$/],
include: [
/200\.html$/,
/\.js$/,
/\.css$/,
/\.(png|jpg|svg|gif|webp|avif)$/,
],
exclude: [/\.esm\.js$/],
})
);
Expand Down

0 comments on commit 691a4e2

Please sign in to comment.