Control webpack compilation progress output - Laravel Mix/Envoy

1.8k Views Asked by At

Using the command like npm run development through Laravel Envoy, makes every line outputted back making hundreds of lines like this in the console:

[remote@server]: <s> [webpack.Progress] 65% building 145/150 modules 5 active /home/remote/example.com/node_modules/date-fns/sub_years/index.js
[remote@server]: <s> [webpack.Progress] 65% building 146/150 modules 4 active /home/remote/example.com/node_modules/date-fns/sub_years/index.js
[remote@server]: <s> [webpack.Progress] 65% building 147/150 modules 3 active /home/remote/example.com/node_modules/date-fns/sub_years/index.js
[remote@server]: <s> [webpack.Progress] 65% building 147/151 modules 4 active /home/remote/example.com/node_modules/array-includes/index.js
[remote@server]: <s> [webpack.Progress] 65% building 148/151 modules 3 active /home/remote/example.com/node_modules/array-includes/index.js
[remote@server]: <s> [webpack.Progress] 65% building 148/152 modules 4 active /home/remote/example.com/node_modules/vue-google-charts/index.js
[remote@server]: <s> [webpack.Progress] 65% building 148/153 modules 5 active /home/remote/example.com/node_modules/@deveodk/vue-toastr/dist/@deveodk/vue-toastr.js
[remote@server]: <s> [webpack.Progress] 65% building 148/154 modules 6 active /home/remote/example.com/node_modules/pluralize/pluralize.js
[remote@server]: <s> [webpack.Progress] 65% building 148/155 modules 7 active /home/remote/example.com/node_modules/vue-js-modal/dist/index.js
[remote@server]: <s> [webpack.Progress] 65% building 148/156 modules 8 active /home/remote/example.com/node_modules/vuex/dist/vuex.esm.js

Is there a way to minimize progress output to only a few lines?

1

There are 1 best solutions below

0
Vladan On BEST ANSWER

Few things are important to understand here:

  • package.json contains npm commands like npm run development, npm run production
  • here's how one of these might look like:

"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

  • the progress output is initiated by --progress argument in above mentioned command
  • the progress output is using ProgressPlugin in the background

The idea is to remove --progress argument from the command so it looks like

"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

but to instantiate it manually as a plugin like so, in webpack.mix.js:

mix.webpackConfig({
    plugins: [
        new webpack.ProgressPlugin((percentage, message) => {
            // An idea to show the line only if percentage is divisible by 5.
            if (percentage * 100 % 5 === 0) {
                console.log(`${(percentage * 100).toFixed()}% ${message}`);
            }
        })
    ],
}); 

Here's how revised output could look like:

0% compiling
10% building
10% building
25% building
40% building
40% building
70% building
70% building
70% finish module graph
70% finish module graph
75% module optimization
70% building
70% building
80% chunk modules optimization
85% chunk reviving
85% chunk reviving
95% emitting
95% emitting

The idea is borrowed from this article explaining how ProgressPlugin works