enhancement: add profiling flag to analyze run

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-06-27 10:43:35 +02:00
parent 1e964839b4
commit 58c2cfe727
3 changed files with 15 additions and 4 deletions

View file

@ -3,11 +3,11 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * 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 path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin') const CopyWebpackPlugin = require('copy-webpack-plugin')
const withBundleAnalyzer = require('@next/bundle-analyzer')({ const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true' enabled: isProfilingMode
}) })
console.log('Node environment is', process.env.NODE_ENV) 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} */ /** @type {import('@svgr/webpack').LoaderOptions} */
const svgrConfig = { const svgrConfig = {
svgoConfig: { svgoConfig: {

View file

@ -7,7 +7,7 @@
"build": "cross-env NODE_ENV=production next build", "build": "cross-env NODE_ENV=production next build",
"build:mock": "cross-env NEXT_PUBLIC_USE_MOCK_API=true 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", "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": "prettier -c \"src/**/*.{ts,tsx,js}\" \"cypress/**/*.{ts,tsx}\"",
"format:fix": "prettier -w \"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", "lint": "eslint --max-warnings=0 --ext .ts,.tsx src",

View file

@ -43,9 +43,16 @@ const isDevMode = process.env.NODE_ENV === 'development'
*/ */
const isProductionMode = process.env.NODE_ENV === 'production' 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 = { module.exports = {
isTestMode, isTestMode,
isMockMode, isMockMode,
isDevMode, isDevMode,
isProductionMode isProductionMode,
isProfilingMode
} }