How to configure Next.js
Next.js is production-ready and handles almost everything, but don't be scared to reach to that config and extend what you need.
module.exports = {
webpack: {
// webpack config properties
plugins: [new MyWebpackPlugin()],
},
env: {
MY_ENV_VAR: process.env.SECRET,
},
};const { PHASE_DEVELOPMENT_SERVER } = require("next/constants");
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_DEVELOPMENT_SERVER) {
console.log("I'm in dev mode");
}
return defaultConfig;
};const { PHASE_PRODUCTION_SERVER } = require("next/constants");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_PRODUCTION_SERVER) {
return {
...defaultConfig,
webpack: {
plugins: [new BundleAnalyzerPlugin()],
},
};
}
return defaultConfig;
};Last updated