How to combine several plugins inside next.config.js file?
You seem to be mixing several configs incorrectly into your Next.js config file.
With next-compose-plugins
To begin with your next.config.js
should only have a single module.exports
, and since you're using next-compose-plugins
, it should roughly follow this structure:
// next.config.js
// Omitting requires for simplicity
module.exports = withPlugins(
[withImages, withSass, withCSS, withVideos, withBundleAnalyzer], // All next plugins go here
// Below is the main Next.js config object
{
images: {
domains: ['cdn.shopify.com']
},
serverRuntimeConfig: {
mySecret: "secret",
secondSecret: process.env.SECOND_SECRET
},
publicRuntimeConfig: {
staticFolder: "/public"
},
// From here everything that's Webpack-related
webpack(config) {
// Add your custom Webpack configs
return config;
}
}
);
Without next-compose-plugins
The same can be achieved without using next-compose-plugins
, by chaining the plugins instead.
// next.config.js
// Omitting requires for simplicity
module.exports = withImages(
withSass(
withCSS(
withVideos(
withBundleAnalyzer({
images: {
domains: ['cdn.shopify.com']
},
serverRuntimeConfig: {
mySecret: "secret",
secondSecret: process.env.SECOND_SECRET
},
publicRuntimeConfig: {
staticFolder: "/public"
},
// From here everything that's Webpack-related
webpack(config) {
// Add your custom Webpack configs
return config;
}
})
)
)
)
);
Finally, the following config belongs to your ESlint config file, and not Next.js config.
// .eslintrc.js
module.exports = {
extends: 'airbnb-base',
rules: {
'arrow-body-style': 0,
},
};
How to combine plugins and other in next js next.config.js
Just like this:
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const nextConfiguration = {
target: 'serverless',
trailingSlash: true
historyApiFallback: true
};
module.exports = withPlugins([optimizedImages], nextConfiguration);
How to combine withPlugins with internatioinalization config in a next.config.js file
What version of Next.JS are you using? I faced the same problem and it was fixed by updating to +10.0.0.
You can see on the i18n documentation on Next that this is the minimum version.
Next.js has built-in support for internationalized (i18n) routing since v10.0.0. You can provide a list of locales, the default locale, and domain-specific locales and Next.js will automatically handle the routing.
More info: https://nextjs.org/docs/advanced-features/i18n-routing
Configure multiple next plugins: withMDX, withBundleAnalyzer
You can setup the config without using next-compose-plugins
as well.
const withMDX = require('@next/mdx')({
extension: /\.mdx$/,
})
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
module.exports = withMDX(withBundleAnalyzer({
// Your Next.js configs, including withMDX-specific options
}))
How do I combine several module.exports in Next.js next.config.js?
You don't need to export two modules, you suppose to export a single configuration object.
Check all possible NextJS configurations here.
const withPWA = require("next-pwa");
module.exports = withPWA({
future: { webpack5: true },
pwa: {
dest: "public",
swSrc: "service-worker.js",
},
env: {
SANITY_DATASET_NAME: process.env.SANITY_DATASET_NAME,
SANITY_PROJECT_ID: process.env.SANITY_PROJECT_ID,
},
});
How to combine Next.js config setting?
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
});
module.exports = withBundleAnalyzer({
images: {
domains: [
"ticket-t01.s3.eu-central-1.amazonaws.com",
"media.istockphoto.com",
],
deviceSizes: [320, 375, 450, 540, 640, 750, 828, 1080, 1200, 1920],
},
reactStrictMode: true,
poweredByHeader: false,
async redirects() {
return [
{
source: "/",
destination: "/hu",
permanent: true,
},
];
},
});
Related Topics
Can You Add Line Breaks to the :After Pseudo Element
Affecting Parent Element of :Focus'D Element (Pure CSS+HTML Preferred)
What Is the Purpose of CSS Prefixes
Why Do Chrome and Firefox Show Different Flex Layout Results
Apply Background-Size to Individual Layer of a Multiple Background
Is It Safe to Use the CSS Rule "Text-Rendering: Optimizelegibility;" on All Text
Multiple Classes in CSS Selector
Moving Dotted Border Using CSS
How to Draw a Partial Circle Outline in CSS (Open Ring Shape)
Customize List Item Bullets Using CSS
CSS { Content: "Text"}, How to Add Tags
Why Does the CSS3 Pseudo ::Selection Not Change the Color for All Parts
Vertically Center Image on Page and Maintain Aspect Ratio on Resize
Parent Selector Nested Inside &:Hover
How to Expand a Child Div to 100% Screen Width If the Container Div Is Smaller