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]" }