Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nextConfiguration not working as expected #42

Open
olikami opened this issue Dec 29, 2020 · 2 comments
Open

nextConfiguration not working as expected #42

olikami opened this issue Dec 29, 2020 · 2 comments

Comments

@olikami
Copy link

olikami commented Dec 29, 2020

In my understanding, this is how my next.config.js should look:

const withPlugins = require('next-compose-plugins');
const nextImages = require('next-images');
const bundleAnalyzer = require('@next/bundle-analyzer')({
	enabled: process.env.ANALYZE === 'true',
});

const nextConfig = {
	async rewrites() {
		return [
			{
				source: '/sitemap.xml',
				destination: '/api/sitemap',
			},
		];
	},
	webpack: (config, options) => {
		config.module.rules.push({
			test: [/\.jpe?g$/, /\.png$/, /\.svg$/],
			use: [
				options.defaultLoaders.babel,
				{
					loader: 'sizeof-loader',
					options: {
						limit: 5000,
						publicPath: '/_next/static/images/',
						outputPath: 'static/images/',
						name: '[name].[hash:8].[ext]',
					},
				},
			],
		});

		return config;
	},
	images: {
		domains: ['<private domain>'],
		imageSizes: [16, 32, 48, 64, 96, 128, 256, 384, 400, 500],
		deviceSizes: [640, 750, 828, 960, 1080, 1200, 1920, 2048, 3840],
	},
};

module.exports = withPlugins([
	[bundleAnalyzer],
	[nextImages],
], nextConfig);

This however break the usage of the next/Image tag.

If found a fix/hack by changing my module.exports:

module.exports = withPlugins([
	[bundleAnalyzer],
	[nextImages],
        nextConfig
]);

This works, but doesn't follow the usage example form the README. This somehow also breaks the bundleAnalyzer.

Am I missing something here? Happy to provide any additional information.

@jadbox
Copy link

jadbox commented Mar 1, 2021

I noticed the same issue, and I was able to fix it with the above solution.

@sa9sha9
Copy link

sa9sha9 commented Mar 21, 2021

Simply, add image config to nextConfig live below and try to re-run yarn dev. It works for me.

const nextConfig =  {
    some: <config>,
    images: {
        domains: ['example.com'],
    },
    webpack: (config, options) =>  {
        <webpack configs>
    } 
}

module.exports = withPlugins([
    [bundleAnalyzer],
], nextConfig), 

No need to add next-images plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants