Skip to content

Commit 7e7f4b9

Browse files
committed
feat(server/client): made progress option available to API
1 parent d346a53 commit 7e7f4b9

File tree

9 files changed

+198
-6
lines changed

9 files changed

+198
-6
lines changed

bin/options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const options = {
3737
describe:
3838
'Inline mode (set to false to disable including client scripts like livereload)',
3939
},
40+
profile: {
41+
type: 'boolean',
42+
describe: 'Print compilation profile data for progress steps',
43+
},
4044
progress: {
4145
type: 'boolean',
4246
describe: 'Print compilation progress in percentage',

bin/webpack-dev-server.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ function startDevServer(config, options) {
9797
throw err;
9898
}
9999

100-
if (options.progress) {
101-
new webpack.ProgressPlugin({
102-
profile: argv.profile,
103-
}).apply(compiler);
104-
}
105-
106100
try {
107101
server = new Server(compiler, options, log);
108102
} catch (err) {

lib/Server.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class Server {
9191
// TODO this.<property> is deprecated (remove them in next major release.) in favor this.options.<property>
9292
this.hot = this.options.hot || this.options.hotOnly;
9393
this.headers = this.options.headers;
94+
this.profile = !!this.options.profile;
9495
this.progress = this.options.progress;
9596

9697
this.serveIndex = this.options.serveIndex;
@@ -147,6 +148,10 @@ class Server {
147148
}
148149

149150
setupProgressPlugin() {
151+
new webpack.ProgressPlugin({
152+
profile: this.profile,
153+
}).apply(this.compiler);
154+
150155
const progressPlugin = new webpack.ProgressPlugin(
151156
(percent, msg, addInfo) => {
152157
percent = Math.floor(percent * 100);

lib/options.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@
255255
}
256256
]
257257
},
258+
"profile": {
259+
"type": "boolean"
260+
},
258261
"progress": {
259262
"type": "boolean"
260263
},
@@ -422,6 +425,7 @@
422425
"pfx": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserverpfx)",
423426
"pfxPassphrase": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpfxpassphrase)",
424427
"port": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserverport)",
428+
"profile": "should be {Boolean}",
425429
"progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverprogress---cli-only)",
426430
"proxy": "should be {Object|Array} (https://webpack.js.org/configuration/dev-server/#devserverproxy)",
427431
"public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublic)",

lib/utils/createConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function createConfig(config, argv, { port }) {
4646
options.liveReload = false;
4747
}
4848

49+
if (argv.profile) {
50+
options.profile = argv.profile;
51+
}
52+
4953
if (argv.progress) {
5054
options.progress = argv.progress;
5155
}

test/cli.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ describe('CLI', () => {
2020
.then((output) => {
2121
expect(output.code).toEqual(0);
2222
expect(output.stderr.includes('0% compiling')).toBe(true);
23+
// should not profile
24+
expect(
25+
output.stderr.includes('ms after chunk modules optimization')
26+
).toBe(false);
27+
done();
28+
})
29+
.catch(done);
30+
});
31+
32+
it('--progress --profile', (done) => {
33+
testBin('--progress --profile')
34+
.then((output) => {
35+
expect(output.code).toEqual(0);
36+
// should profile
37+
expect(
38+
output.stderr.includes('ms after chunk modules optimization')
39+
).toBe(true);
2340
done();
2441
})
2542
.catch(done);

test/e2e/Progress.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
/* eslint-disable
4+
no-undef
5+
*/
6+
const fs = require('fs');
7+
const path = require('path');
8+
const testServer = require('../helpers/test-server');
9+
const reloadConfig = require('../fixtures/reload-config/webpack.config');
10+
const runBrowser = require('../helpers/run-browser');
11+
12+
describe('client progress', () => {
13+
describe('using hot', () => {
14+
const cssFilePath = path.resolve(__dirname, '../temp/main.css');
15+
beforeAll((done) => {
16+
fs.writeFileSync(
17+
cssFilePath,
18+
'body { background-color: rgb(0, 0, 255); }'
19+
);
20+
const options = {
21+
port: 9000,
22+
host: '0.0.0.0',
23+
inline: true,
24+
hot: true,
25+
progress: true,
26+
watchOptions: {
27+
poll: 500,
28+
},
29+
};
30+
testServer.startAwaitingCompilation(reloadConfig, options, done);
31+
});
32+
33+
afterAll((done) => {
34+
testServer.close(done);
35+
});
36+
37+
describe('on browser client', () => {
38+
jest.setTimeout(30000);
39+
40+
it('should console.log progress', (done) => {
41+
runBrowser().then(({ page, browser }) => {
42+
const res = [];
43+
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
44+
fs.writeFileSync(
45+
cssFilePath,
46+
'body { background-color: rgb(255, 0, 0); }'
47+
);
48+
page.waitFor(10000).then(() => {
49+
expect(res).toMatchSnapshot();
50+
browser.close().then(done);
51+
});
52+
});
53+
54+
page.goto('http://localhost:9000/main');
55+
page.on('console', ({ _text }) => {
56+
res.push(_text);
57+
});
58+
});
59+
});
60+
});
61+
});
62+
});
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`client progress using hot on browser client should console.log progress 1`] = `
4+
Array [
5+
"[HMR] Waiting for update signal from WDS...",
6+
"[WDS] Hot Module Replacement enabled.",
7+
"[WDS] Live Reloading enabled.",
8+
"[WDS] App updated. Recompiling...",
9+
"[WDS] 0% - compiling.",
10+
"[WDS] 10% - building (0/0 modules).",
11+
"[WDS] 10% - building (0/0 modules).",
12+
"[WDS] 10% - building (0/1 modules).",
13+
"[WDS] 40% - building (0/1 modules).",
14+
"[WDS] 40% - building (1/1 modules).",
15+
"[WDS] 70% - building (1/1 modules).",
16+
"[WDS] 70% - finish module graph.",
17+
"[WDS] 70% - finish module graph (FlagDependencyExportsPlugin).",
18+
"[WDS] 70% - sealing.",
19+
"[WDS] 70% - sealing (WarnCaseSensitiveModulesPlugin).",
20+
"[WDS] 71% - basic dependencies optimization.",
21+
"[WDS] 72% - dependencies optimization.",
22+
"[WDS] 72% - advanced dependencies optimization.",
23+
"[WDS] 73% - after dependencies optimization.",
24+
"[WDS] 70% - chunk graph.",
25+
"[WDS] 71% - after chunk graph.",
26+
"[WDS] 71% - after chunk graph (WebAssemblyModulesPlugin).",
27+
"[WDS] 73% - optimizing.",
28+
"[WDS] 74% - basic module optimization.",
29+
"[WDS] 74% - module optimization.",
30+
"[WDS] 75% - advanced module optimization.",
31+
"[WDS] 75% - after module optimization.",
32+
"[WDS] 76% - basic chunk optimization.",
33+
"[WDS] 76% - basic chunk optimization (EnsureChunkConditionsPlugin).",
34+
"[WDS] 76% - basic chunk optimization (RemoveParentModulesPlugin).",
35+
"[WDS] 76% - basic chunk optimization (RemoveEmptyChunksPlugin).",
36+
"[WDS] 76% - basic chunk optimization (MergeDuplicateChunksPlugin).",
37+
"[WDS] 76% - chunk optimization.",
38+
"[WDS] 77% - advanced chunk optimization.",
39+
"[WDS] 77% - advanced chunk optimization (SplitChunksPlugin).",
40+
"[WDS] 77% - advanced chunk optimization (RemoveEmptyChunksPlugin).",
41+
"[WDS] 77% - after chunk optimization.",
42+
"[WDS] 78% - module and chunk tree optimization.",
43+
"[WDS] 78% - after module and chunk tree optimization.",
44+
"[WDS] 79% - basic chunk modules optimization.",
45+
"[WDS] 79% - chunk modules optimization.",
46+
"[WDS] 80% - advanced chunk modules optimization.",
47+
"[WDS] 80% - after chunk modules optimization.",
48+
"[WDS] 81% - module reviving.",
49+
"[WDS] 81% - module reviving (RecordIdsPlugin).",
50+
"[WDS] 81% - module order optimization.",
51+
"[WDS] 82% - advanced module order optimization.",
52+
"[WDS] 82% - before module ids.",
53+
"[WDS] 82% - before module ids (NamedModulesPlugin).",
54+
"[WDS] 83% - module ids.",
55+
"[WDS] 83% - module id optimization.",
56+
"[WDS] 84% - module id optimization.",
57+
"[WDS] 84% - chunk reviving.",
58+
"[WDS] 84% - chunk reviving (RecordIdsPlugin).",
59+
"[WDS] 85% - chunk order optimization.",
60+
"[WDS] 85% - chunk order optimization (OccurrenceOrderChunkIdsPlugin).",
61+
"[WDS] 85% - before chunk ids.",
62+
"[WDS] 85% - before chunk ids (NamedChunksPlugin).",
63+
"[WDS] 86% - chunk id optimization.",
64+
"[WDS] 86% - after chunk id optimization.",
65+
"[WDS] 87% - record modules.",
66+
"[WDS] 87% - record modules (RecordIdsPlugin).",
67+
"[WDS] 87% - record chunks.",
68+
"[WDS] 87% - record chunks (RecordIdsPlugin).",
69+
"[WDS] 88% - hashing.",
70+
"[WDS] 88% - content hashing.",
71+
"[WDS] 88% - content hashing (JavascriptModulesPlugin).",
72+
"[WDS] 89% - after hashing.",
73+
"[WDS] 89% - after hashing (HotModuleReplacementPlugin).",
74+
"[WDS] 89% - record hash.",
75+
"[WDS] 90% - module assets processing.",
76+
"[WDS] 90% - chunk assets processing.",
77+
"[WDS] 91% - additional chunk assets processing.",
78+
"[WDS] 91% - additional chunk assets processing (HotModuleReplacementPlugin).",
79+
"[WDS] 91% - recording.",
80+
"[WDS] 91% - recording (HotModuleReplacementPlugin).",
81+
"[WDS] 92% - additional asset processing.",
82+
"[WDS] 92% - chunk asset optimization.",
83+
"[WDS] 93% - after chunk asset optimization.",
84+
"[WDS] 93% - asset optimization.",
85+
"[WDS] 94% - after asset optimization.",
86+
"[WDS] 94% - after seal.",
87+
"[WDS] 95% - emitting.",
88+
"[WDS] 98% - after emitting.",
89+
"[WDS] 100% - Compilation completed.",
90+
"[WDS] App hot update...",
91+
"[HMR] Checking for updates on the server...",
92+
"[HMR] Updated modules:",
93+
"[HMR] - ../../temp/main.css",
94+
"[HMR] - ../../../node_modules/css-loader/dist/cjs.js!../../temp/main.css",
95+
"",
96+
"[HMR] App is up to date.",
97+
]
98+
`;

test/options.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ describe('options', () => {
303303
success: ['', 0, null],
304304
failure: [false],
305305
},
306+
profile: {
307+
success: [false],
308+
failure: [''],
309+
},
306310
progress: {
307311
success: [false],
308312
failure: [''],

0 commit comments

Comments
 (0)