Fail Storybook build if there are webpack compilation warnings
Create a Webpack plugin which looks for warnings at the end of the build. Reference doc: https://webpack.js.org/contribute/writing-a-plugin/
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const path = require('path');
|
||||
const WebpackPluginFailBuildOnWarning = require('./webpack-plugin-fail-build-on-warning');
|
||||
|
||||
module.exports = {
|
||||
stories: [
|
||||
@@ -53,6 +54,9 @@ module.exports = {
|
||||
({ constructor }) => constructor.name !== 'ProgressPlugin',
|
||||
);
|
||||
|
||||
// Fail storybook build if there are webpack warnings
|
||||
config.plugins.push(new WebpackPluginFailBuildOnWarning())
|
||||
|
||||
return config;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class WebpackPluginFailBuildOnWarning {
|
||||
apply(compiler) {
|
||||
compiler.hooks.done.tap('FailBuildOnWarning', stats => {
|
||||
if (stats.compilation.warnings.length > 0) {
|
||||
process.on('beforeExit', () => {
|
||||
console.log(`You have ${stats.compilation.warnings.length} warning(s) in your webpack build. Exiting process as error.`)
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebpackPluginFailBuildOnWarning;
|
||||
Reference in New Issue
Block a user