From 4d9122e20db6a65d0c2d44c8676f5e90bc3643f7 Mon Sep 17 00:00:00 2001 From: Daniels Lee Date: Fri, 16 Sep 2022 16:14:47 -0700 Subject: [PATCH 1/2] fix: ensure devserver client options are configurable When a custom `webpackConfig.devServer.client` option is set, they are currently being overridden by the `baseConfig.client` field. Ensure that field is extendible by consumers while also ensuring the base config values stay fixed. https://github.com/styleguidist/react-styleguidist/issues/2033 --- src/scripts/create-server.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/scripts/create-server.ts b/src/scripts/create-server.ts index 814f9b010..fcc593d4c 100644 --- a/src/scripts/create-server.ts +++ b/src/scripts/create-server.ts @@ -36,6 +36,10 @@ export default function createServer( const webpackDevServerConfig: Configuration = { ...webpackConfig.devServer, ...baseConfig, + client: { + ...webpackConfig.devServer.client, + ...baseConfig.client, + }, }; const compiler = webpack(webpackConfig); From f96c454dc1b028fa8c9f90fc92f606562893cf35 Mon Sep 17 00:00:00 2001 From: Daniels Lee Date: Mon, 19 Sep 2022 12:36:23 -0700 Subject: [PATCH 2/2] fix: ensure all devServer options are overridable; add tests --- src/scripts/__tests__/create-server.spec.ts | 44 +++++++++++++++++++++ src/scripts/create-server.ts | 11 ++---- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/scripts/__tests__/create-server.spec.ts b/src/scripts/__tests__/create-server.spec.ts index 76b0c63e4..4b1c91494 100644 --- a/src/scripts/__tests__/create-server.spec.ts +++ b/src/scripts/__tests__/create-server.spec.ts @@ -61,3 +61,47 @@ test('createServer should return an object containing a development Webpack comp expect(output.chunkFilename).toBe('build/[name].js'); done(); }); + +test('createServer should apply some base config options', () => { + process.chdir('test/apps/basic'); + const config = { + ...getConfig(), + serverHost: 'localhost', + serverPort: 6000, + }; + const result = createServer(config, 'development'); + expect(result).toBeTruthy(); + expect(result.compiler).toBeTruthy(); + expect(result.compiler.options.devServer).toMatchObject({ + host: 'localhost', + port: 6000, + compress: true, + hot: true, + client: { logging: 'none' }, + webSocketServer: 'ws', + }); +}); + +test('createServer should allow overriding default devServer options', () => { + process.chdir('test/apps/basic'); + const config = { + ...getConfig(), + webpackConfig: { + devServer: { + client: { + overlay: false, + progress: true, + }, + }, + }, + }; + const result = createServer(config, 'development'); + expect(result).toBeTruthy(); + expect(result.compiler).toBeTruthy(); + expect(result.compiler.options.devServer).toMatchObject({ + client: { + overlay: false, + progress: true, + }, + }); +}); diff --git a/src/scripts/create-server.ts b/src/scripts/create-server.ts index fcc593d4c..3b4272c0f 100644 --- a/src/scripts/create-server.ts +++ b/src/scripts/create-server.ts @@ -33,17 +33,14 @@ export default function createServer( }, }; - const webpackDevServerConfig: Configuration = { - ...webpackConfig.devServer, + // Allow custom devServer options to override base config. + webpackConfig.devServer = { ...baseConfig, - client: { - ...webpackConfig.devServer.client, - ...baseConfig.client, - }, + ...webpackConfig.devServer, }; const compiler = webpack(webpackConfig); - const devServer = new WebpackDevServer(webpackDevServerConfig, compiler); + const devServer = new WebpackDevServer(webpackConfig.devServer, compiler); // User defined customizations if (config.configureServer) {