Created
August 5, 2022 09:27
-
-
Save huksley/516943aa861dc3ed72b39516cd8a019f to your computer and use it in GitHub Desktop.
Use instead of next-images package https://www.npmjs.com/package/next-images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "svg", "gif", "ico", "webp", "jp2", "avif"]; | |
/** | |
* Send images as URL over certain threshould. You don't need this for next/Image component. | |
* Alternative to next-images package. | |
* | |
* @type {import('next').NextConfig} | |
**/ | |
module.exports = config => () => { | |
return { | |
...config, | |
webpack(config, options) { | |
const { isServer } = options; | |
config.module.rules.push({ | |
test: new RegExp(`\.(${IMAGE_EXTENSIONS.join("|")})$`), | |
// Next.js already handles url() in css/sass/scss files | |
issuer: /\.\w+(?<!(s?c|sa)ss)$/i, | |
use: [ | |
{ | |
loader: "url-loader", | |
options: { | |
limit: 8192, | |
fallback: "file-loader", | |
outputPath: `${isServer ? "../" : ""}static/images/`, | |
publicPath: `/_next/static/images/`, | |
name: "[name]-[hash].[ext]" | |
} | |
} | |
] | |
}); | |
if (typeof config.webpack === "function") { | |
return config.webpack(config, options); | |
} | |
return config; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment