1 | import webpack from "webpack";
|
2 | export function progressPlugin() {
|
3 | let currentMessage = null;
|
4 | let lastPercentage = 0;
|
5 | const startTime = Date.now();
|
6 | const messageSteps = {
|
7 | compiling: "Compilation started",
|
8 | building: "Building",
|
9 | "finish module graph": "Finishing module graph",
|
10 | optimizing: "Running optimizations",
|
11 | hashing: "Hashing",
|
12 | "chunk asset optimization": "Minimizing",
|
13 | "after chunk asset optimization": "Creating source maps",
|
14 | emitting: "Emitting files"
|
15 | };
|
16 | return new webpack.ProgressPlugin((percentage, msg, ...args) => {
|
17 |
|
18 |
|
19 |
|
20 | if (!Object.keys(messageSteps).includes(msg)) {
|
21 | return;
|
22 | }
|
23 | if (currentMessage !== msg || Math.abs(lastPercentage - percentage) > 0.07) {
|
24 | let postfix = "";
|
25 | if (msg === "building") {
|
26 | postfix = ` - ${args[0]} ${args[1]}`;
|
27 | } |
28 |
|
29 |
|
30 | console.log(` ${`[${((Date.now() - startTime) / 1000).toFixed(2)} s]`.padEnd(10)} ${(percentage * 100)
|
31 | .toFixed(0)
|
32 | .padStart(3)}% ${messageSteps[msg]} ${postfix}`);
|
33 | currentMessage = msg;
|
34 | lastPercentage = percentage;
|
35 | }
|
36 | });
|
37 | }
|
38 | //# sourceMappingURL=progressPlugin.js.map |
\ | No newline at end of file |