From b3d14816bb6f93cbb5d6acc8418a19fe46dfdec3 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sun, 22 Mar 2020 05:06:10 +0300 Subject: [PATCH] fix(v2): do not force terminate building if client bundle failed in development mode (#2437) --- packages/docusaurus/src/webpack/client.ts | 44 ++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/docusaurus/src/webpack/client.ts b/packages/docusaurus/src/webpack/client.ts index 13038c1433..f9e8f1ccb3 100644 --- a/packages/docusaurus/src/webpack/client.ts +++ b/packages/docusaurus/src/webpack/client.ts @@ -17,6 +17,7 @@ import LogPlugin from './plugins/LogPlugin'; export function createClientConfig(props: Props): Configuration { const isProd = process.env.NODE_ENV === 'production'; + const isBuilding = process.argv[2] === 'build'; const config = createBaseConfig(props, false); const clientConfig = merge(config, { @@ -32,26 +33,6 @@ 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({ @@ -60,5 +41,28 @@ export function createClientConfig(props: Props): Configuration { ], }); + // When building include the plugin to force terminate building if errors happened in the client bundle. + if (isBuilding) { + clientConfig.plugins!.push({ + 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); + } + }); + }, + }); + } + return clientConfig; }