如果在监视模式下以最小输出运行,如何将当前时间戳添加到 webpack4 中的输出

eur*_*at7 3 continuous-integration webpack webpack-4

当您执行 CI 并使用 webpack 打开一个小窗口来监视您的文件时,有时很难看出 webpack 是否已检测到您的更改(此处为 Windows 10)。

所以我用 --display=minimal 减少了输出。但现在输出只是“33个模块”。看起来都一样。

我想在输出中添加时间戳,以便我可以区分它们。

webpack3 有一个解决方案,它会在 webpack4 中给你一个 DeprecationWarning :

Tapable.plugin is deprecated. Use new API on `.hooks` instead
Run Code Online (Sandbox Code Playgroud)

所以请不要使用这个:

--do not use this in webpack4--  

module.exports = {
  plugins: [
    this.plugin('done',function(){/*...*/})
  ]
}

--do not use this in webpack4--
Run Code Online (Sandbox Code Playgroud)

我错过了一条迁移路径。

eur*_*at7 5

这是webpack4的解决方案:

\n\n
// webpack.config.js\nmodule.exports = {\n  plugins: [\n    function() {\n      this.hooks.done.tap('BuildStatsPlugin', function() {\n        console.log(new Date().toLocaleTimeString());\n      });\n    }\n  ]\n};\n
Run Code Online (Sandbox Code Playgroud)\n\n

所以如果你现在...

\n\n
webpack --watch --display=minimal\n
Run Code Online (Sandbox Code Playgroud)\n\n

...每当你更改文件之一时,webpack 都会重新编译,并且只在控制台输出中添加两行:

\n\n
webpack is watching the files\xe2\x80\xa6\n\n22:05:34\n   33 modules\n22:16:04\n   33 modules\n
Run Code Online (Sandbox Code Playgroud)\n