文章目录
一、先说结论
问题原因:
- 该bug源于babel-loader自身,使用JSON.stringify(config)生成哈希码作为命中缓存条件之一,所以function(不仅function,js基础不赘述)中配置变化无法读取。源码中关键代码如下:
/** node_modules/babel-loader/lib/cache.js 文件 */
const filename = function (source, identifier, options) {
// md4 hashing is not supported starting with node v17.0.0
const majorNodeVersion = parseInt(process.versions.node.split(".")[0], 10);
let hashType = "md4";
if (majorNodeVersion >= 17) {
hashType = "md5";
}
// 这里function丢失,导致新哈希码命中旧哈希码
const hash = crypto.createHash(hashType);
const contents = JSON.stringify({
source,
options,
identifier