Last active
November 25, 2022 14:00
-
-
Save ValentaTomas/1f7d1a775cf56eff45bf958dbd9c2d8c to your computer and use it in GitHub Desktop.
Compose Next.js plugins without nesting and additional variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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