gpt4 book ai didi

webpack - watchOptions.ignored 和 webpack.WatchIgnorePlugin 有什么区别

转载 作者:行者123 更新时间:2023-12-04 01:13:54 24 4
gpt4 key购买 nike

使用webpack和watch时,比如使用webpack-dev-server时似乎(至少)有两种不同的方法可以将文件排除在外。我真的找不到关于这两种配置之间差异以及它们为何不同的任何文档。有谁知道为什么?一种方法是首选吗?我应该打开一个问题和/或拉取请求来改进文档吗?

我最近遇到的第一次运行时多次触发 watch 的情况通过添加 watchIgnorePlugin 得到修复。并且未由 watchOptions.ignored 修复

webpack.WatchIgnorePlugin

Ignore the specified files, i.e. those matching the provided paths or regular expressions, while in watch mode.

new webpack.WatchIgnorePlugin(paths)

Options

  • paths (array): A list of RegExps or absolute paths to directories or' files that should be ignored.

https://webpack.js.org/plugins/watch-ignore-plugin/



watchOptions.ignored

For some systems, watching many file systems can result in a lot of CPU or memory usage. It is possible to exclude a huge folder like node_modules:

 ignored: /node_modules/

It is also possible to use anymatch patterns:

 ignored: "files/**/*.js"

https://webpack.js.org/configuration/watch/

最佳答案

WatchIgnorePlugin -plugin 支持应忽略的目录或文件的正则表达式列表或绝对路径。
watchOptions.ignored -option 支持 anymatch -patterns,包括正则表达式、glob、字符串或将字符串作为参数并返回真值或假值的函数。

如果您在 Windows 上工作,这可能就是原因 watchOptions.ignored不适合你:

Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.

关于webpack - watchOptions.ignored 和 webpack.WatchIgnorePlugin 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48361956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com