From bf70e8137477c19c7ec2178634a9d0318b161c81 Mon Sep 17 00:00:00 2001 From: Simon Boudrias Date: Fri, 28 Sep 2018 15:25:16 +0800 Subject: [PATCH] Allow setting `inlineImageLimit` value to 0 `0` being falsy, the previous default parameter logic was overwriting the value. This disallowed user to disable image inlining. --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 77f7907..d3fa7dc 100644 --- a/index.js +++ b/index.js @@ -2,24 +2,23 @@ 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' ) } - const assetPrefix = nextConfig.assetPrefix || ""; - const limit = nextConfig.inlineImageLimit || 8192; - config.module.rules.push({ test: /\.(jpe?g|png|svg|gif|ico)$/, use: [ { loader: "url-loader", options: { - limit, + limit: nextConfig.inlineImageLimit, fallback: "file-loader", - publicPath: `${assetPrefix}/_next/static/images/`, + publicPath: `${nextConfig.assetPrefix}/_next/static/images/`, outputPath: `${isServer ? "../" : ""}static/images/`, name: "[name]-[hash].[ext]" }