Skip to content

Commit b10dd27

Browse files
aszx87410Li Hu
andauthored
Add removeOriginalExtension option (#158)
Co-authored-by: Li Hu <li.hu@onedegree.hk>
1 parent d570274 commit b10dd27

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ Default: `'[name]-[hash].[ext]'`
548548
The filename of the optimized images.
549549
Make sure you keep the `[hash]` part so they receive a new filename if the content changes.
550550

551+
#### removeOriginalExtension
552+
553+
Type: `boolean`<br>
554+
Default: `false`
555+
556+
When images converted to WebP on the fly, `.webp` was append to the filename. For example, `test.png` became `test.png.webp`. If you want to have only one filename extension like `test.webp`, you can set this option to `true`.
557+
551558
#### optimizeImagesInDev
552559

553560
Type: `boolean`<br>
@@ -714,6 +721,7 @@ module.exports = withPlugins([
714721
imagesFolder: 'images',
715722
imagesName: '[name]-[hash].[ext]',
716723
handleImages: ['jpeg', 'png', 'svg', 'webp', 'gif'],
724+
removeOriginalExtension: false,
717725
optimizeImages: true,
718726
optimizeImagesInDev: false,
719727
mozjpeg: {

lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const getConfig = nextConfig => ({
1111
handleImages: ['jpeg', 'png', 'svg', 'webp', 'gif'],
1212
imagesFolder: 'images',
1313
imagesName: '[name]-[hash].[ext]',
14+
removeOriginalExtension: false,
1415
inlineImageLimit: 8192,
1516
defaultImageLoader: 'img-loader',
1617
mozjpeg: {},

lib/loaders/webp-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const applyWebpLoader = (webpackConfig, nextConfig, optimize, isServer, detectLo
6060
const getWebpResourceQuery = (nextConfig, isServer) => {
6161
const urlLoaderOptions = getUrlLoaderOptions(nextConfig, isServer);
6262
const imageName = urlLoaderOptions.name.indexOf('[ext]') >= 0
63-
? urlLoaderOptions.name.replace('[ext]', '[ext].webp')
63+
? urlLoaderOptions.name.replace('[ext]', nextConfig.removeOriginalExtension ? 'webp' : '[ext].webp')
6464
: `${urlLoaderOptions.name}.webp`;
6565

6666
return {

0 commit comments

Comments
 (0)