Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): do not force terminate building if client bundle failed in development mode #2437

Merged
merged 1 commit into from
Mar 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions packages/docusaurus/src/webpack/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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({
Expand All @@ -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;
}