Created
March 12, 2019 06:10
-
-
Save arefaslani/7dd427b6a21421d38f9d276b0759efb8 to your computer and use it in GitHub Desktop.
Next Images with ns-ignore
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
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: /\.(jpe?g|png|svg|gif|ico|webp)$/, | |
exclude: nextConfig.exclude, | |
resourceQuery: /(?!(ni-ignore))/i, | |
use: [ | |
{ | |
loader: "url-loader", | |
options: { | |
limit: nextConfig.inlineImageLimit, | |
fallback: "file-loader", | |
publicPath: `${nextConfig.assetPrefix}/_next/static/images/`, | |
outputPath: `${isServer ? "../" : ""}static/images/`, | |
name: "[name]-[hash].[ext]" | |
} | |
} | |
] | |
}); | |
if (typeof nextConfig.webpack === 'function') { | |
return nextConfig.webpack(config, options) | |
} | |
return config | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment