From 58c2cfe727f496c9101dd27cd1536a0a53db4f3c Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Tue, 27 Jun 2023 10:43:35 +0200 Subject: [PATCH] enhancement: add profiling flag to analyze run Signed-off-by: Erik Michelson --- frontend/next.config.js | 8 ++++++-- frontend/package.json | 2 +- frontend/src/utils/test-modes.js | 9 ++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) 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 }