Skip to content

Commit 952a188

Browse files
fix: the --progress option with the serve command (#2265)
1 parent e6f9943 commit 952a188

File tree

5 files changed

+31
-62
lines changed

5 files changed

+31
-62
lines changed

packages/serve/__tests__/mergeOptions.test.ts

-34
This file was deleted.

packages/serve/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ServeCommand {
5151
const processors: Array<(opts: Record<string, any>) => void> = [];
5252

5353
for (const optionName in options) {
54-
if (optionName === 'hot' || optionName === 'progress') {
54+
if (optionName === 'hot') {
5555
devServerOptions[optionName] = options[optionName];
5656
webpackOptions[optionName] = options[optionName];
5757
} else {

packages/serve/src/mergeOptions.ts

-24
This file was deleted.

packages/serve/src/startDevServer.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { utils } from 'webpack-cli';
2-
3-
import mergeOptions from './mergeOptions';
1+
import { devServerOptionsType } from './types';
42

53
/**
64
*
@@ -48,6 +46,19 @@ export default async function startDevServer(compiler, cliOptions, logger): Prom
4846

4947
const servers = [];
5048
const usedPorts: number[] = [];
49+
const mergeOptions = (cliOptions: devServerOptionsType, devServerOptions: devServerOptionsType): devServerOptionsType => {
50+
// CLI options should take precedence over devServer options,
51+
// and CLI options should have no default values included
52+
const options = { ...devServerOptions, ...cliOptions };
53+
54+
if (devServerOptions.client && cliOptions.client) {
55+
// the user could set some client options in their devServer config,
56+
// then also specify client options on the CLI
57+
options.client = { ...devServerOptions.client, ...cliOptions.client };
58+
}
59+
60+
return options;
61+
};
5162

5263
for (const devServerOpts of devServerOptions) {
5364
const options = mergeOptions(cliOptions, devServerOpts);

test/serve/basic/serve-basic.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ describe('basic serve usage', () => {
6161
expect(stdout).not.toContain('HotModuleReplacementPlugin');
6262
});
6363

64+
it('should work with the "--progress" option', async () => {
65+
const { stderr, stdout } = await runServe(['--progress'], __dirname);
66+
67+
expect(stderr).toContain('webpack.Progress');
68+
expect(stdout).toContain('main.js');
69+
expect(stdout).not.toContain('HotModuleReplacementPlugin');
70+
});
71+
72+
it('should work with the "--progress" option using the "profile" value', async () => {
73+
const { stderr, stdout } = await runServe(['--progress', 'profile'], __dirname);
74+
75+
expect(stderr).toContain('webpack.Progress');
76+
expect(stdout).toContain('main.js');
77+
expect(stdout).not.toContain('HotModuleReplacementPlugin');
78+
});
79+
6480
it('should work with flags', async () => {
6581
const { stderr, stdout } = await runServe(['--hot'], __dirname);
6682

0 commit comments

Comments
 (0)