如何关闭Webpack中带固定旧时间戳的重复编译成功日志?
解决Webpack重复输出旧时间戳编译成功日志的问题
精简后的3次Webpack编译日志如下:
Webpack bundle stats plugin took 10174 ms 2024-06-14 13:42:29: webpack compiled successfully 2024-06-14 13:40:31: webpack compiled successfully Webpack bundle stats plugin took 9450 ms 2024-06-14 13:43:32: webpack compiled successfully 2024-06-14 13:40:31: webpack compiled successfully Webpack bundle stats plugin took 9633 ms 2024-06-14 13:44:09: webpack compiled successfully 2024-06-14 13:40:31: webpack compiled successfully日志中重复出现带固定旧时间戳
2024-06-14 13:40:31的webpack compiled successfully条目,干扰实际编译时间判断,可通过以下方法解决:
调整Webpack Bundle Stats Plugin配置
日志中存在插件耗时记录,大概率是该插件导致重复日志输出。修改插件配置,禁用冗余日志:const BundleStatsPlugin = require('webpack-bundle-stats-plugin').BundleStatsPlugin; module.exports = { plugins: [ new BundleStatsPlugin({ logStats: false, // 关闭插件自带的成功日志 stats: { all: false, compiled: true, timings: true // 仅保留必要的编译时间信息 } }) ] };自定义Webpack日志过滤规则
通过Webpack的stats.logging选项直接过滤指定旧日志:module.exports = { stats: { logging: (level, message) => { // 过滤包含固定旧时间戳的日志条目 return !message.includes('2024-06-14 13:40:31'); } } };清理Webpack缓存
旧日志可能来自缓存,尝试:- 编译时添加
--no-cache参数:webpack --no-cache - 手动删除项目中的缓存目录(如
node_modules/.cache)
- 编译时添加
排查其他Webpack插件
检查项目中其他插件(如html-webpack-plugin、copy-webpack-plugin)的配置,确认是否有触发重复日志的选项,调整为仅输出当前编译状态。
内容的提问来源于stack exchange,提问作者Deepak Yadav
相关产品推荐
相关产品推荐

