javascript - buildDependencies targets folder instead of file
问题描述
For caching (type: 'filesystem'
), when i use
buildDependencies: {
config: [__filename],
}
and rebuild after a minimal change, I get cache to be used:
[webpack.cache.PackFileCacheStrategy] restore cache container: 75.650361 ms
[webpack.cache.PackFileCacheStrategy] check build dependencies: 38.511852 ms
[webpack.cache.PackFileCacheStrategy] restore cache content metadata: 7.851668 ms
However, if i simply add one more file to buildDependencies
, e.g. like this (same, if i use a new property):
buildDependencies: {
config: [__filename, path.resolve(__dirname, 'tsconfig.json')],
}
I suddenly get a cache invalidation (although tsconfig.json
didn't change, neither did webpack.config.js
, i obviously rebuilt in between):
[webpack.cache.PackFileCacheStrategy] restore cache container: 79.482314 ms
[webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] C:\some\nice\folder invalidated because hashes differ (somehash != someotherhash)
[webpack.cache.PackFileCacheStrategy] Restored pack from C:\some\nice\folder\cachefolder\cachename.pack, but build dependencies have changed.
[webpack.cache.PackFileCacheStrategy] check build dependencies: 593.564325 ms
Note that it mentions that a path ending with a folder (the project folder) invalidated, although i supposedly specified a file as dependency. The resulting build time is around twice as long.
What am i doing wrong here? Why does webpack invalidate the cache here, although none of the dependencies changed?
解决方案
到目前为止,Webpack 不支持 中的非代码文件buildDependencies
,并且ts-loader
似乎没有正确声明tsconfig.json
为依赖项(通过加载程序的通道),因此首先需要这样做。一个后备然后使用整个文件夹。
幸运的是,这两个都应该在未来的版本中得到修复:webpack 将允许.json
文件进入buildDependencies
(如果我没记错的话v5.14.0
,它现在已经可用),并ts-loader
希望告诉 webpack tsconfig.json
(在未来的某个版本中),所以它会工作即使没有手动设置依赖关系。一些相关的日志和错误也会发生变化,以提供更多信息。
推荐阅读
- python - Python:如何并行化用于具有许多函数输入的嵌套 for 循环中的函数?
- dependency-injection - 如何在责任链模式中使用 Unity IoC 注入多个不同的依赖项?
- google-analytics - 将自定义视图保存为默认值
- python - 如何在 Python 中使用 GLPK 为目标函数设置时间限制或松弛参数?
- typescript - Typescript 泛型:给定键 K 和对象 T,约束 T[K] 的类型
- excel - 在一列中查找类似日期然后计算最小值/最大值之间的差异的公式
- android - Android:使用 Viewmodel 缓存来自 EditText 的瞬态 UI 数据的最佳方式
- python - DRF 不会向浏览器发送原始 JSON 字符串。它返回一个 JSON 字符串,想要绕过调用 json.load
- c++ - 捕获异常后如何退出程序执行
- botframework - 有没有办法信任 Bot Framework Skype for Business ChannelData 中的某些内容来确定用户来自给定域?