From f0572f7b9fe42db0100251e6b2079af9257cc026 Mon Sep 17 00:00:00 2001 From: David Wallace Date: Mon, 2 Dec 2024 15:00:29 +0100 Subject: [PATCH] build(webpack): add build:dist, fails on warnings #1197 Signed-off-by: David Wallace --- .github/workflows/ci.yml | 2 +- package.json | 1 + webpack.config.js | 34 +++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 255aff784f..0f72bb6def 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: with: node-version: 18 cache: npm - - run: npm ci && npm run build:prod + - run: npm ci && npm run build:dist # build the wheel - uses: actions/setup-python@v5 with: diff --git a/package.json b/package.json index d2e79d2b81..066ec6aa30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "rdmo", "scripts": { + "build:dist": "webpack --config webpack.config.js --mode production --env ignore-perf --fail-on-warnings", "build:prod": "webpack --config webpack.config.js --mode production", "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 d1d630dd32..7ae8bf9371 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') @@ -116,16 +117,39 @@ const productionConfig = { optimization: { minimize: true, minimizer: [new TerserPlugin()] - } + }, +} + +const ignorePerformanceWarnings = { + performance: { + hints: false // Suppress performance warnings in prod + }, + ignoreWarnings: [ // ignore performance issues + { 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) => { return configList.map(config => { - if (argv.mode === 'development') { - return merge(config, baseConfig, developmentConfig) - } else { - return merge(config, baseConfig, productionConfig) + switch (argv.mode) { + + case 'development': + // used for build and watch + return merge(config, baseConfig, developmentConfig) + + case 'production': + if (env && env['ignore-perf']) { + // build:dist will ignore performance warnings but fails on other warnings + return merge(config, baseConfig, productionConfig, ignorePerformanceWarnings) + } + // build:prod + return merge(config, baseConfig, productionConfig) + + default: + throw new Error('Invalid mode') } }) }