在react-scripts正式支持webpack 5之前,我使用的是webpack-5-react-scripts
,现在迁移到了官方的react-scripts。在迁移过程中,我遇到了一个与缓存有关的问题。
webpack 5引入了很多新特性,其中之一就是persistent caching。持久缓存允许快速重建,但由于文档中提到的原因,默认情况下它是禁用的。但是如果我们设置正确的话,我们可以配置它。
之前我使用了以下缓存和缓存失效配置(最有可能覆盖react-scripts的该高速缓存配置):
if (options.caching && options.caching.enabled) {
config.cache = {
type: 'filesystem',
version: process.env.GIT_REV,
buildDependencies: {
config: options.caching.buildDependencies,
},
};
const snapshotSettings = process.env.CI ? { hash: true } : { timestamp: true };
config.snapshot = {
immutablePaths: [],
buildDependencies: snapshotSettings,
module: snapshotSettings,
resolve: snapshotSettings,
resolveBuildDependencies: snapshotSettings,
};
}
这是使用了该高速缓存,但也根据构建/本地环境将快照设置设置为基于内容或时间戳。
我检查了react-scripts的webpack配置,发现我们只使用缓存配置,但没有任何快照设置。
在这种情况下,如何React做该高速缓存失效?另外,🙈我是否正确理解了React脚本中缓存+快照的设置?
1条答案
按热度按时间6mw9ycah1#
这个问题在React的github讨论中得到了回答:https://github.com/facebook/create-react-app/discussions/13101#discussioncomment-5686864