Skip to content

Commit

Permalink
build(webpack): build prod fails on warnings #1197
Browse files Browse the repository at this point in the history
Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Dec 2, 2024
1 parent 2ab41f6 commit 9815207
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "rdmo",
"scripts": {
"build:prod": "webpack --config webpack.config.js --mode production",
"build:prod": "webpack --config webpack.config.js --mode production --env ignore-perf --fail-on-warnings",
"build:warn": "webpack --config webpack.config.js --mode production --fail-on-warnings",
"build": "webpack --config webpack.config.js --mode development",
"watch": "webpack --config webpack.config.js --mode development --watch"
},
Expand Down
32 changes: 27 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -116,16 +117,37 @@ 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':
return merge(config, baseConfig, developmentConfig)

case 'production':
if (env && env['ignore-perf']) {
// build:prod will ignore performance warnings but fails on other warnings
return merge(config, baseConfig, productionConfig, ignorePerformanceWarnings)
}
return merge(config, baseConfig, productionConfig)

default:
throw new Error('Invalid mode')
}
})
}

0 comments on commit 9815207

Please sign in to comment.