115

I would like to know if there's a configuration option to tell webpack to only log the "important information" to the terminal. Pretty much just errors and warnings, not all of this:

output of terminal with webpack

There's just so much output! Would love to suppress the common stuff and only have webpack output the warnings/errors. Would like a solution for webpack, webpack-dev-server, and karma-webpack.

Note: I tried noInfo: true and quiet: true but that didn't seem to do the trick.


Edit: I'm thinking this may not be possible, so I've created an issue on github: https://github.com/webpack/webpack/issues/1191

kentcdodds
  • 27,113
  • 32
  • 108
  • 187
  • 2
    Looks like on the command line the `noInfo` option is actually the inverse of `--info`, which defaults to `true` so if you run `webpack-dev-server --info false` it should get you closer to where you want to be. – naartjie Jun 10 '15 at 22:57
  • 2
    That appears to do it for webpack-dev-server... Now if only I could get it for my tests :-) – kentcdodds Jun 11 '15 at 12:38
  • 2
    If anyone's curious, here's what I execute now: `NODE_ENV=development webpack-dev-server --content-base app/ --port 8888 --colors --progress --info false` – kentcdodds Jun 11 '15 at 12:39
  • 2
    This works as well: `NODE_ENV=development webpack-dev-server --content-base app/ --port 8888 --colors --progress --no-info` – kentcdodds Jun 11 '15 at 12:55
  • Ah, `--no-info` is good to know, thanks – naartjie Jun 11 '15 at 16:28
  • Is there any chance to provide these options via the webpack.config.js? All I see in the code is how the options are read from argv – Lukas Zech Jul 09 '15 at 06:06
  • Yeah, me too @LukasZech, I'd like to be able to add this to my config for karma. Original question still not answered on this one. I don't believe it's currently possible, but I have an issue for it: https://github.com/webpack/webpack/issues/1191 – kentcdodds Jul 09 '15 at 14:39

12 Answers12

67

In my webpack config, Doing this reduced my incremental build time by 8 seconds and silenced output. The main one is chunks: false

Play with it to fit your needs

module.exports = {
 devServer: {
  stats: {
    colors: true,
    hash: false,
    version: false,
    timings: false,
    assets: false,
    chunks: false,
    modules: false,
    reasons: false,
    children: false,
    source: false,
    errors: false,
    errorDetails: false,
    warnings: false,
    publicPath: false
  }
 }
}
TetraDev
  • 16,074
  • 6
  • 60
  • 61
59

Actually, these two work great.

stats: 'errors-only',

at the end of the exported object.

One could also use stats: 'minimal', it only outputs when errors or new compilation happen. Read more from the official documentation of Webpack.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ahmad Awais
  • 33,440
  • 5
  • 74
  • 56
33

I don't know when this feature was added, but I just noticed in the docs that you can add a webpackMiddleware property and on that you can specify noInfo: true. Doing this removes all the noise! But you still see output when there are errors. Yay!

kentcdodds
  • 27,113
  • 32
  • 108
  • 187
17

You've got the --display option that enables you to choose a level of information quantity you want displayed.

From webpack --help:

--display: Select display preset
[string] [choices: "", "verbose", "detailed", "normal", "minimal", "errors-only", "none"]

If you want to configure the informations displayed more precisely, you can also configure your webpack with the stats field in your webpack.config.js.

papillon
  • 1,807
  • 2
  • 19
  • 39
10

These days noInfo quiet and stats have been replaced by infrastructureLogging in the root of your Webpack config:

// webpack.config.js
...
infrastructureLogging: {
  level: 'error',
},
bendytree
  • 13,095
  • 11
  • 75
  • 91
9

If you are using the webpack-dev-middleware you can throw the noInfo: true in an object as the second parameter. Also assuming you also have a node/express server running.

enter image description here

Cheers.

leocreatini
  • 676
  • 1
  • 9
  • 18
  • I'm posting this for other people with the similar issue on a slightly different configuration because Google Search is leading them here. – leocreatini Jan 03 '16 at 19:37
  • 2
    You can also add `noInfo: true` to the `devServer` configuration item in webpack.config.js. – Chad Johnson Jan 06 '16 at 10:37
  • Only one that worked for me. Also works on webpackMiddleware. Thank you, crap output was driving me crazy. – Doa Feb 16 '17 at 21:35
8

Webpack

  ...
  stats: {
    modules: false,
  },
  ...

Dev Server

  ...
  devServer: {
    stats: {
      modules: false,
    },
  },
  ...

Reference

https://webpack.js.org/configuration/stats/

Chris
  • 54,599
  • 30
  • 149
  • 186
4

What you're interested in here is stats module (part) of the Webpack. Basically, it's this module that produces the output. The output by default mostly contains list of assets, and list of modules. You can hide modules with --hide-modules directive. Regarding assets, no similar option exists. But there are presets. You can specify preset with --display option. And preset that hides assets is... none.

There is another way to influence stats: webpack.config.js. Add stats: {assets: false, modules: false} to reduce output significantly. Or stats: 'none' to silence Webpack entirely. Not that I recommend it. Generally errors-only is a way to go. To make it affect webpack-dev-server put it under devServer key.

Webpack 2.x doesn't have --display option. And the only way to hide modules is --hide-modules switch. By that I mean that specifying stats: 'errors-only' or stats: {modules: false} in config has no effect. Since this piece of code overrides all that.

For webpack-dev-server there are also --no-info and --quiet options.

Some more insight into how it works. webpack-cli creates outputOptions object. When compilation finishes, it converts stats to string and outputs it. Stats.toString converts stats to json, then converts json to string. Here you can see the defaults.

x-yuri
  • 16,722
  • 15
  • 114
  • 161
2

Recommend stats config below, this will keep significant logs and remove useless info.

stats: {
  cached: false,
  cachedAssets: false,
  chunks: false,
  chunkModules: false,
  chunkOrigins: false,
  modules: false
}
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
aaron.xiao
  • 198
  • 8
1

If you're using the Webpack API directly, and you're calling stats.toString(), then you can pass parameters to keep down the noise:

webpack(config).watch(100, (err, stats) => {
  console.log(stats.toString({chunks: false}))
})
Kai Sellgren
  • 27,954
  • 10
  • 75
  • 87
1

With Webpack 5 I had to remove stats from devServer and add it as a base config property. All the relevant stats can be found here for additional configuration https://webpack.js.org/configuration/stats/

https://webpack.js.org/configuration/other-options/#infrastructurelogging

The following worked for me: (I use friendly-errors)

{
  stats: 'errors-only',
  infrastructureLogging: {
    level: 'none',
  },
  devServer:{
    // other config
  }
}

You can also be more specific about what to display using an object.

{
  stats: {
    entrypoints: false,
    colors: true,
    assets: false,
    chunks: false,
    modules: false,
  },
  infrastructureLogging: {
    level: 'none',
  },
  devServer:{
    // other config
  }
}
KR34T1V
  • 433
  • 2
  • 15
0

Webpack v5

The "most silent" configuration:

infrastructureLogging: { level: 'error' },
stats: 'minimal',

Docs: infrastructureLogging, stats.

lonix
  • 14,255
  • 23
  • 85
  • 176