Skip to content

Commit 06129a1

Browse files
authored
feat(webpack-cli): add progress bar for progress flag (#1238)
* feat: add progress bar in progress * chore: remove async * chore: remove readline * chore: lint
1 parent 6cc6a49 commit 06129a1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

packages/webpack-cli/lib/utils/Compiler.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const webpack = require('webpack');
22
const logger = require('./logger');
3+
const { cyanBright, greenBright } = require('chalk');
34
const { CompilerOutput } = require('./CompilerOutput');
45

56
class Compiler {
@@ -15,17 +16,26 @@ class Compiler {
1516

1617
compilation.hooks.beforeRun.tap('webpackProgress', () => {
1718
if (outputOptions.progress) {
18-
let tmpMsg;
19+
process.stdout.write('\n');
1920
const defaultProgressPluginHandler = (percent, msg) => {
2021
percent = Math.floor(percent * 100);
21-
if (percent === 100) {
22-
msg = 'Compilation completed';
22+
process.stdout.clearLine();
23+
process.stdout.cursorTo(0);
24+
if (percent !== undefined) {
25+
process.stdout.write(' (');
26+
for (let i = 0; i <= 100; i += 10) {
27+
if (i <= percent) {
28+
process.stdout.write(greenBright('#'));
29+
} else {
30+
process.stdout.write('#');
31+
}
32+
}
33+
process.stdout.write(`) ${percent}% : `);
34+
process.stdout.write(`${cyanBright(msg)}`);
35+
if (percent === 100) {
36+
process.stdout.write(`${cyanBright('Complilation completed\n')}`);
37+
}
2338
}
24-
25-
if (msg && tmpMsg != msg) {
26-
logger.info(percent + '% ' + msg);
27-
}
28-
tmpMsg = msg;
2939
};
3040
if (!progressPluginExists) {
3141
new ProgressPlugin(defaultProgressPluginHandler).apply(compilation);

0 commit comments

Comments
 (0)