如何停止显示Webpack的构建日志?

时间:2018-07-28 15:05:48

标签: webpack nuxt.js

我要停止显示这样的构建日志:

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]         

.
.
.

我当时使用ava来运行测试。但是这些日志让我很烦。我试图在stats中设置webpack nuxt.config.js的配置,但是没有用。有人可以提供任何帮助吗?

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

更新:以下内容可以隐藏资产日志,但仍显示警告:

// 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/
      ]
    },
    ...
  }
 ...
}

但这不会隐藏警告:

 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

2 个答案:

答案 0 :(得分:2)

您可以这样做

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
 }

         ...
        }

答案 1 :(得分:0)

以下是您的 webpack 配置的建议:

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

要禁用的关键是hashversiontimingsassetschunks

这应该减少构建时间并抑制日志记录。

注意:此建议来自Webpack: silence output。我不能将这个问题标记为重复,因为它有很多。 :)