diff --git a/packages/storybook/.storybook/main.js b/packages/storybook/.storybook/main.js index c187dc5f56..cf003d0981 100644 --- a/packages/storybook/.storybook/main.js +++ b/packages/storybook/.storybook/main.js @@ -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; }, }; diff --git a/packages/storybook/.storybook/webpack-plugin-fail-build-on-warning.js b/packages/storybook/.storybook/webpack-plugin-fail-build-on-warning.js new file mode 100644 index 0000000000..4359035161 --- /dev/null +++ b/packages/storybook/.storybook/webpack-plugin-fail-build-on-warning.js @@ -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;