跳到主要内容

watchOptions

watchOptions 一组用来定制 watch 模式的选项

语法


小知识
  1. 只有开启watch模式,watchOptions才有意义。
module.exports = {
watch: true,
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 2000,
poll: 1000,
},
};

配置项如下所示:

  • poll: 通过传递 true 开启 polling,或者指定毫秒为单位进行轮询。

    module.exports = {
    //...
    watchOptions: {
    poll: 1000, // 每秒检查一次变动
    }
    };
  • stdin: 当 stdin 流结束时停止监听。

  • ignored: 对于某些系统,监听大量文件会导致大量的 CPU 或内存占用。可以使用正则排除像 node_modules 如此庞大的文件夹

    watchOptions: {
    ignored: /node_modules/,
    }
  • followSymlinks: 根据软链接查找文件。这通常是不需要的,因为 webpack 已经使用 resolve.symlinks 解析了软链接。

  • aggregateTimeout: 监听到变化发生后延迟 xx 时间后再去执行(类似于防抖)