Skip to content

Commit b5397a5

Browse files
authored
Merge pull request #1203 from rdmorganiser/1197-npm-build-warnings-in-ci
1197 npm build warnings in ci
2 parents 2ab41f6 + f0572f7 commit b5397a5

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
with:
6262
node-version: 18
6363
cache: npm
64-
- run: npm ci && npm run build:prod
64+
- run: npm ci && npm run build:dist
6565
# build the wheel
6666
- uses: actions/setup-python@v5
6767
with:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "rdmo",
33
"scripts": {
4+
"build:dist": "webpack --config webpack.config.js --mode production --env ignore-perf --fail-on-warnings",
45
"build:prod": "webpack --config webpack.config.js --mode production",
56
"build": "webpack --config webpack.config.js --mode development",
67
"watch": "webpack --config webpack.config.js --mode development --watch"

webpack.config.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const developmentConfig = {
108108

109109
// special config for production
110110
const productionConfig = {
111+
bail: true, // Stop the build on errors
111112
plugins: [
112113
new webpack.DefinePlugin({
113114
'process.env.NODE_ENV': JSON.stringify('production')
@@ -116,16 +117,39 @@ const productionConfig = {
116117
optimization: {
117118
minimize: true,
118119
minimizer: [new TerserPlugin()]
119-
}
120+
},
121+
}
122+
123+
const ignorePerformanceWarnings = {
124+
performance: {
125+
hints: false // Suppress performance warnings in prod
126+
},
127+
ignoreWarnings: [ // ignore performance issues
128+
{ message: /performance recommendations/ },
129+
{ message: /asset size limit/ },
130+
{ message: /entrypoint size limit/ }
131+
]
120132
}
121133

122134
// combine config depending on the provided --mode command line option
123135
module.exports = (env, argv) => {
124136
return configList.map(config => {
125-
if (argv.mode === 'development') {
126-
return merge(config, baseConfig, developmentConfig)
127-
} else {
128-
return merge(config, baseConfig, productionConfig)
137+
switch (argv.mode) {
138+
139+
case 'development':
140+
// used for build and watch
141+
return merge(config, baseConfig, developmentConfig)
142+
143+
case 'production':
144+
if (env && env['ignore-perf']) {
145+
// build:dist will ignore performance warnings but fails on other warnings
146+
return merge(config, baseConfig, productionConfig, ignorePerformanceWarnings)
147+
}
148+
// build:prod
149+
return merge(config, baseConfig, productionConfig)
150+
151+
default:
152+
throw new Error('Invalid mode')
129153
}
130154
})
131155
}

0 commit comments

Comments
 (0)