packages/website/scripts/withFiles.js
/**
* @author twopluszero
* https://github.com/twopluszero/next-images
*/
module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
const { isServer } = options;
nextConfig = Object.assign({ inlineImageLimit: 8192, assetPrefix: "" }, nextConfig);
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}
config.module.rules.push({
test: /\.(woff|woff2|eot|ttf|otf)$/,
issuer: {
// Next.js already handles url() in css/sass/scss files
test: /\.\w+(?<!(s?c|sa)ss)$/i,
},
exclude: nextConfig.exclude,
use: [
{
loader: require.resolve("url-loader"),
options: {
limit: nextConfig.inlineImageLimit,
fallback: require.resolve("file-loader"),
publicPath: `${nextConfig.assetPrefix}/_next/static/images/`,
outputPath: `${isServer ? "../" : ""}static/images/`,
name: "[name]-[hash].[ext]",
esModule: nextConfig.esModule || false
}
}
]
});
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
}
})
}