load @next/bundle-analyzer conditionally if env was set (#999)

pull/1002/head^2
Anton Podviaznikov 2021-10-20 02:08:58 -07:00 committed by GitHub
parent 362e8114a0
commit ade88700fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -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), {