diff --git a/package.json b/package.json index d2e79d2b8..9e3927578 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "rdmo", "scripts": { "build:prod": "webpack --config webpack.config.js --mode production", + "build:testing": "webpack --config webpack.config.js --mode production --env testing --fail-on-warnings", "build": "webpack --config webpack.config.js --mode development", "watch": "webpack --config webpack.config.js --mode development --watch" }, diff --git a/webpack.config.js b/webpack.config.js index d1d630dd3..4aff24993 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -108,6 +108,7 @@ const developmentConfig = { // special config for production const productionConfig = { + bail: true, // Stop the build on errors plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') @@ -115,17 +116,46 @@ const productionConfig = { ], optimization: { minimize: true, - minimizer: [new TerserPlugin()] - } + minimizer: [new TerserPlugin()], + }, +} + +// additional config for testing +const testingConfig = { + bail: true, // Stop on errors or critical warnings + performance: { + hints: false // Suppress performance warnings in testing + }, + ignoreWarnings: [ + { message: /performance recommendations/ }, + { message: /asset size limit/ }, + { message: /entrypoint size limit/ } + ] } // combine config depending on the provided --mode command line option module.exports = (env, argv) => { + // Determine if testing mode is enabled + const isTesting = env && env.testing + return configList.map(config => { if (argv.mode === 'development') { + // Return the development configuration directly return merge(config, baseConfig, developmentConfig) + } else if (argv.mode === 'production') { + // Start with the base production configuration + let finalConfig = merge(config, baseConfig, productionConfig) + + // Add testing-specific configuration if in testing mode + if (isTesting) { + finalConfig = merge(finalConfig, testingConfig) + } + + return finalConfig } else { - return merge(config, baseConfig, productionConfig) + throw new Error( + 'Invalid configuration: use \'development\', \'production\', or \'--env testing\' for testing builds.' + ) } }) }