4

I want is to stop displaying build logs like this:

Hash: 5a2a3d23f88174970ed8
Version: webpack 3.12.0
Time: 22209ms
                                         Asset       Size  Chunks                    Chunk Names
   pages/widgets/index.51838abe9967a9e0b5ff.js    1.17 kB      10  [emitted]         pages/widgets/index
                       img/icomoon.7f1da5a.svg    5.38 kB          [emitted]         
                     fonts/icomoon.2d429d6.ttf    2.41 kB          [emitted]         
           img/fontawesome-webfont.912ec66.svg     444 kB          [emitted]  [big]  
         fonts/fontawesome-webfont.b06871f.ttf     166 kB          [emitted]         
                        img/mobile.8891a7c.png    39.6 kB          [emitted]         
                   img/play_button.6b15900.png    14.8 kB          [emitted]         
                  img/keyword-back.f95e10a.jpg    43.4 kB          [emitted]         
                    fonts/icomoon.16db67c.woff    2.49 kB          [emitted]         
                     fonts/icomoon.2fcbf50.eot    2.58 kB          [emitted]         
         fonts/fontawesome-webfont.674f50d.eot     166 kB          [emitted]         
        fonts/fontawesome-webfont.fee66e7.woff      98 kB          [emitted]         

.
.
.

I was using ava to run tests. But these logs are annoying me. I tried to set webpack stats config in nuxt.config.js, but it is not working. Can someone provide any help?

// Does not work
{
  ...
  build: {
    ...
    extend (config, { isClient }) {
      ...
      if (process.env.NODE_ENV === 'test') {
        config.stats = 'errors-only'
      }
    }
  }
 ...
}

Update: The following can hide assets logs, but it still shows warnings:

// Works, but does not hide warnings
{
  ...
  build: {
    stats: process.env.NODE_ENV === 'test' ? 'errors-only' {
      chunks: false,
      children: false,
      modules: false,
      colors: true,
      assets: true,
      warnings: true,
      errors: true,
      excludeAssets: [
        /.map$/,
        /index\..+\.html$/,
        /vue-ssr-client-manifest.json/
      ]
    },
    ...
  }
 ...
}

But this does not hide the warnings:

 WARNING  Compiled with 2 warnings

 warning  

asset size limit: The following asset(s) exceed the recommended size limit (300 kB).
This can impact web performance.
Assets: 
  img/fontawesome-webfont.912ec66.svg (444 kB)
  vendor.4db9bb219a2a9c02d939.js (726 kB)
  app.f14777ec0017fec245a3.js (546 kB)

 warning  

entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (1 MB). This can impact web performance.
Entrypoints:
  app (1.27 MB)
      manifest.4eb49c6cde9aa836f4d4.js
      vendor.4db9bb219a2a9c02d939.js
      app.f14777ec0017fec245a3.js
Dipu
  • 6,999
  • 4
  • 31
  • 48

2 Answers2

2

You could do something like this

build: {

          stats: process.env.NODE_ENV === 'test' ? 'errors-only' : { // default config here for non test build. Nuxt default could be seen here
 https://github.com/nuxt/nuxt.js/blob/567dc860c1393ccf0e849b032b69edddd5b6b7bb/lib/common/nuxt.config.js#L93
 }

         ...
        }
Aldarund
  • 17,312
  • 5
  • 73
  • 104
  • it works! except the `exceed the recommended size limit` warnings, it does hide all printed assets. they should have mentioned these configs in their documentation. – Dipu Aug 26 '18 at 09:34
  • do you know how to hide the warnings? it would make your answer complete – Dipu Aug 26 '18 at 09:56
  • @Dipu you could provide full config instead of errors-only, where you could set it individually e.g. warnings: false . Or you could just set it to false – Aldarund Aug 26 '18 at 10:53
  • I tested with full-configs, it does not work. warnings are there no matter what – Dipu Aug 26 '18 at 12:06
  • @Dipu well, false will disable whole stat module. – Aldarund Aug 26 '18 at 13:02
  • I have done that. but the warnings will not stop. what is actually going on here! is nuxt modifying the stats property elsewhere? – Dipu Aug 26 '18 at 14:12
  • @Dipu I tried with nuxt-edge and I don't see anything from stats module with false. – Aldarund Aug 27 '18 at 19:03
  • I was using `nuxt 1.4.1`. they had some bug I guess – Dipu Aug 30 '18 at 07:30
  • 1
    @Dipu might be, you can try use edge, it will be released soon and stable already – Aldarund Aug 30 '18 at 08:34
1

Here's a suggestion for your webpack config:

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
  }
 }
}

The key ones to disable are hash, version, timings, assets, chunks.

This should reduce build times and suppress logging.

Note: this suggestion comes from Webpack: silence output. I couldn't flag this question as a duplicate though, as it has a bounty. :)

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72