【问题标题】:buildDependencies targets folder instead of filebuildDependencies 目标文件夹而不是文件
【发布时间】:2021-04-15 21:52:59
【问题描述】:

用于缓存 (type: 'filesystem'),当我使用时

buildDependencies: {
  config: [__filename],
}

并在进行最小更改后重建,我得到了要使用的缓存:

[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

但是,如果我只是向buildDependencies 添加一个文件,例如像这样(相同,如果我使用新属性):

buildDependencies: {
  config: [__filename, path.resolve(__dirname, 'tsconfig.json')],
}

我突然得到一个缓存失效(虽然tsconfig.json没有改变,webpack.config.js也没有,我显然在两者之间重建):

[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

请注意,它提到以文件夹(项目文件夹)结尾的路径无效,尽管我应该将文件指定为依赖项。生成的构建时间大约是原来的两倍。

我在这里做错了什么?为什么webpack这里的缓存无效,虽然没有任何依赖改变?

【问题讨论】:

    标签: javascript node.js webpack


    【解决方案1】:

    到目前为止,Webpack 不支持buildDependencies 中的非代码文件,并且ts-loader 似乎没有正确地将tsconfig.json 声明为依赖项(通过加载程序的通道),因此首先需要这样做。然后回退使用整个文件夹。

    幸运的是,这两个都应该在即将到来的版本中得到修复:webpack 将允许 buildDependencies 中的 .json 文件(如果我没记错的话 v5.14.0,它现在已经可用),而 ts-loader 将希望告诉 webpack tsconfig.json(在未来的某个版本中),这样即使不手动设置依赖项也可以工作。一些相关的日志和错误也会发生变化,以提供更多信息。

    【讨论】:

      猜你喜欢
      • 2016-10-23
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多