From c9ace3b7ed05781aa602abcaa1b3285a92cdb680 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sun, 8 Mar 2020 18:19:31 +0300 Subject: [PATCH] fix(v2): force terminate building if client bundle failed (#2345) * fix(v2): force terminate building if client bundle failed * Use ES6 import so tests pass --- packages/docusaurus/src/webpack/client.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/docusaurus/src/webpack/client.ts b/packages/docusaurus/src/webpack/client.ts index 81c593019c..13038c1433 100644 --- a/packages/docusaurus/src/webpack/client.ts +++ b/packages/docusaurus/src/webpack/client.ts @@ -4,6 +4,8 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ + +import chalk from 'chalk'; import path from 'path'; import {Configuration} from 'webpack'; import merge from 'webpack-merge'; @@ -30,6 +32,26 @@ export function createClientConfig(props: Props): Configuration { runtimeChunk: true, }, plugins: [ + // Plugin to force terminate building if errors happened in the client bundle + { + apply: compiler => { + compiler.hooks.done.tap('client:done', stats => { + if (stats.hasErrors()) { + console.log( + chalk.red( + 'Client bundle compiled with errors therefore further build is impossible.', + ), + ); + + stats.toJson('errors-only').errors.forEach(e => { + console.error(e); + }); + + process.exit(1); + } + }); + }, + }, new ChunkAssetPlugin(), // Show compilation progress bar and build time. new LogPlugin({