diff --git a/frontend/next.config.js b/frontend/next.config.js index edde6ec72..63b785717 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -3,11 +3,11 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ -const { isMockMode, isTestMode, isProductionMode} = require('./src/utils/test-modes') +const { isMockMode, isTestMode, isProductionMode, isProfilingMode } = require('./src/utils/test-modes') const path = require('path') const CopyWebpackPlugin = require('copy-webpack-plugin') const withBundleAnalyzer = require('@next/bundle-analyzer')({ - enabled: process.env.ANALYZE === 'true' + enabled: isProfilingMode }) console.log('Node environment is', process.env.NODE_ENV) @@ -31,6 +31,10 @@ if (isMockMode) { `) } +if (isProfilingMode) { + console.info('This build contains the bundle analyzer and profiling metrics.') +} + /** @type {import('@svgr/webpack').LoaderOptions} */ const svgrConfig = { svgoConfig: { diff --git a/frontend/package.json b/frontend/package.json index 7d711b4f6..ec2c2ecad 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,7 +7,7 @@ "build": "cross-env NODE_ENV=production next build", "build:mock": "cross-env NEXT_PUBLIC_USE_MOCK_API=true next build", "build:test": "cross-env NODE_ENV=test NEXT_PUBLIC_TEST_MODE=true next build", - "analyze": "cross-env ANALYZE=true yarn build", + "analyze": "cross-env ANALYZE=true yarn build --profile", "format": "prettier -c \"src/**/*.{ts,tsx,js}\" \"cypress/**/*.{ts,tsx}\"", "format:fix": "prettier -w \"src/**/*.{ts,tsx,js}\" \"cypress/**/*.{ts,tsx}\"", "lint": "eslint --max-warnings=0 --ext .ts,.tsx src", diff --git a/frontend/src/utils/test-modes.js b/frontend/src/utils/test-modes.js index 0530dff54..1376e6a4a 100644 --- a/frontend/src/utils/test-modes.js +++ b/frontend/src/utils/test-modes.js @@ -43,9 +43,16 @@ const isDevMode = process.env.NODE_ENV === 'development' */ const isProductionMode = process.env.NODE_ENV === 'production' +/** + * Defines if the current runtime contains the bundle analyzer and profiling metrics. + * @type boolean + */ +const isProfilingMode = !!process.env.ANALYZE && isPositiveAnswer(process.env.ANALYZE) + module.exports = { isTestMode, isMockMode, isDevMode, - isProductionMode + isProductionMode, + isProfilingMode }