Skip to content

Instantly share code, notes, and snippets.

@ValentaTomas
Last active November 25, 2022 14:00
Show Gist options
  • Save ValentaTomas/1f7d1a775cf56eff45bf958dbd9c2d8c to your computer and use it in GitHub Desktop.
Save ValentaTomas/1f7d1a775cf56eff45bf958dbd9c2d8c to your computer and use it in GitHub Desktop.
Compose Next.js plugins without nesting and additional variables
function isPlugin(maybePlugin) {
return typeof maybePlugin === 'function'
}
function composePlugins(...plugins) {
return (baseConfig) => plugins
.filter(isPlugin)
.reduce((c, plugin) => plugin(c), baseConfig)
}
// Usage
const pluginWrapper = composePlugins(
process.env.ANALYZE && require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true' }),
)
const config = {
reactStrictMode: false,
}
module.exports = pluginWrapper(config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment