Skip to content

Commit

Permalink
fix: ensure devserver client options are configurable (#2034)
Browse files Browse the repository at this point in the history
* 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.

#2033

* fix: ensure all devServer options are overridable; add tests
  • Loading branch information
dannobytes authored Oct 6, 2022
1 parent 80b5e84 commit f1a0c21
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
44 changes: 44 additions & 0 deletions src/scripts/__tests__/create-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
});
7 changes: 4 additions & 3 deletions src/scripts/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export default function createServer(
},
};

const webpackDevServerConfig: Configuration = {
...webpackConfig.devServer,
// Allow custom devServer options to override base config.
webpackConfig.devServer = {
...baseConfig,
...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) {
Expand Down

0 comments on commit f1a0c21

Please sign in to comment.