Skip to content

Commit

Permalink
Add removeOriginalExtension option (cyrilwanner#158)
Browse files Browse the repository at this point in the history
Co-authored-by: Li Hu <[email protected]>
  • Loading branch information
aszx87410 and Li Hu committed May 31, 2020
1 parent d570274 commit b10dd27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ Default: `'[name]-[hash].[ext]'`
The filename of the optimized images.
Make sure you keep the `[hash]` part so they receive a new filename if the content changes.

#### removeOriginalExtension

Type: `boolean`<br>
Default: `false`

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`.

#### optimizeImagesInDev

Type: `boolean`<br>
Expand Down Expand Up @@ -714,6 +721,7 @@ module.exports = withPlugins([
imagesFolder: 'images',
imagesName: '[name]-[hash].[ext]',
handleImages: ['jpeg', 'png', 'svg', 'webp', 'gif'],
removeOriginalExtension: false,
optimizeImages: true,
optimizeImagesInDev: false,
mozjpeg: {
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const getConfig = nextConfig => ({
handleImages: ['jpeg', 'png', 'svg', 'webp', 'gif'],
imagesFolder: 'images',
imagesName: '[name]-[hash].[ext]',
removeOriginalExtension: false,
inlineImageLimit: 8192,
defaultImageLoader: 'img-loader',
mozjpeg: {},
Expand Down
2 changes: 1 addition & 1 deletion lib/loaders/webp-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const applyWebpLoader = (webpackConfig, nextConfig, optimize, isServer, detectLo
const getWebpResourceQuery = (nextConfig, isServer) => {
const urlLoaderOptions = getUrlLoaderOptions(nextConfig, isServer);
const imageName = urlLoaderOptions.name.indexOf('[ext]') >= 0
? urlLoaderOptions.name.replace('[ext]', '[ext].webp')
? urlLoaderOptions.name.replace('[ext]', nextConfig.removeOriginalExtension ? 'webp' : '[ext].webp')
: `${urlLoaderOptions.name}.webp`;

return {
Expand Down

0 comments on commit b10dd27

Please sign in to comment.