Skip to content

Commit f1a0c21

Browse files
authored
fix: ensure devserver client options are configurable (#2034)
* 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
1 parent 80b5e84 commit f1a0c21

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/scripts/__tests__/create-server.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,47 @@ test('createServer should return an object containing a development Webpack comp
6161
expect(output.chunkFilename).toBe('build/[name].js');
6262
done();
6363
});
64+
65+
test('createServer should apply some base config options', () => {
66+
process.chdir('test/apps/basic');
67+
const config = {
68+
...getConfig(),
69+
serverHost: 'localhost',
70+
serverPort: 6000,
71+
};
72+
const result = createServer(config, 'development');
73+
expect(result).toBeTruthy();
74+
expect(result.compiler).toBeTruthy();
75+
expect(result.compiler.options.devServer).toMatchObject({
76+
host: 'localhost',
77+
port: 6000,
78+
compress: true,
79+
hot: true,
80+
client: { logging: 'none' },
81+
webSocketServer: 'ws',
82+
});
83+
});
84+
85+
test('createServer should allow overriding default devServer options', () => {
86+
process.chdir('test/apps/basic');
87+
const config = {
88+
...getConfig(),
89+
webpackConfig: {
90+
devServer: {
91+
client: {
92+
overlay: false,
93+
progress: true,
94+
},
95+
},
96+
},
97+
};
98+
const result = createServer(config, 'development');
99+
expect(result).toBeTruthy();
100+
expect(result.compiler).toBeTruthy();
101+
expect(result.compiler.options.devServer).toMatchObject({
102+
client: {
103+
overlay: false,
104+
progress: true,
105+
},
106+
});
107+
});

src/scripts/create-server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ export default function createServer(
3333
},
3434
};
3535

36-
const webpackDevServerConfig: Configuration = {
37-
...webpackConfig.devServer,
36+
// Allow custom devServer options to override base config.
37+
webpackConfig.devServer = {
3838
...baseConfig,
39+
...webpackConfig.devServer,
3940
};
4041

4142
const compiler = webpack(webpackConfig);
42-
const devServer = new WebpackDevServer(webpackDevServerConfig, compiler);
43+
const devServer = new WebpackDevServer(webpackConfig.devServer, compiler);
4344

4445
// User defined customizations
4546
if (config.configureServer) {

0 commit comments

Comments
 (0)