From ade88700fce3528a3970073bd3a2f9f7c8942b0a Mon Sep 17 00:00:00 2001 From: Anton Podviaznikov Date: Wed, 20 Oct 2021 02:08:58 -0700 Subject: [PATCH] load @next/bundle-analyzer conditionally if env was set (#999) --- next.config.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/next.config.js b/next.config.js index d083673491..8bcd99b10d 100644 --- a/next.config.js +++ b/next.config.js @@ -2,10 +2,6 @@ const withTM = require("next-transpile-modules")(["react-timezone-select"]); const { i18n } = require("./next-i18next.config"); -const withBundleAnalyzer = require("@next/bundle-analyzer")({ - enabled: process.env.ANALYZE === "true", -}); - // So we can test deploy previews preview if (process.env.VERCEL_URL && !process.env.BASE_URL) { process.env.BASE_URL = "https://" + process.env.VERCEL_URL; @@ -46,7 +42,16 @@ if (process.env.GOOGLE_API_CREDENTIALS && !validJson(process.env.GOOGLE_API_CRED ); } -const plugins = [withBundleAnalyzer, withTM]; +const plugins = []; +if (process.env.ANALYZE === "true") { + // only load dependency if env `ANALYZE` was set + const withBundleAnalyzer = require("@next/bundle-analyzer")({ + enabled: true, + }); + plugins.push(withBundleAnalyzer); +} + +plugins.push(withTM); // prettier-ignore module.exports = () => plugins.reduce((acc, next) => next(acc), {