From fc0df304c0d96d19f1b2b137057721b5e175fe2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 16 Dec 2021 12:02:29 +0100 Subject: [PATCH] feat(core): allow plugins to customize/override Webpack devServer config (#6107) --- packages/docusaurus/src/commands/start.ts | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index d6bad0d75f..ce6f003ab9 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -166,8 +166,20 @@ export default async function start( } }); + const compiler = webpack(config); + if (process.env.E2E_TEST) { + compiler.hooks.done.tap('done', (stats) => { + if (stats.hasErrors()) { + console.log('E2E_TEST: Project has compiler errors.'); + process.exit(1); + } + console.log('E2E_TEST: Project can compile.'); + process.exit(0); + }); + } + // https://webpack.js.org/configuration/dev-server - const devServerConfig: WebpackDevServer.Configuration = { + const defaultDevServerConfig: WebpackDevServer.Configuration = { hot: cliOptions.hotOnly ? 'only' : true, liveReload: false, client: { @@ -222,17 +234,10 @@ export default async function start( }, }; - const compiler = webpack(config); - if (process.env.E2E_TEST) { - compiler.hooks.done.tap('done', (stats) => { - if (stats.hasErrors()) { - console.log('E2E_TEST: Project has compiler errors.'); - process.exit(1); - } - console.log('E2E_TEST: Project can compile.'); - process.exit(0); - }); - } + // Allow plugin authors to customize/override devServer config + const devServerConfig: WebpackDevServer.Configuration = merge( + [defaultDevServerConfig, config.devServer].filter(Boolean), + ); const devServer = new WebpackDevServer(devServerConfig, compiler); devServer.startCallback(() => {