使用 create-expo-app 时如何更改 webpack-config.js 中的哈希函数?

dna*_*ana 8 node.js webpack react-native expo

遵循本指南:/sf/answers/5142568371/

我尝试了答案中给出的两个选项,但它们都不起作用。我安装了 @expo\webpack-config 并在 webpack-config.js 文件中实现了更改,如下所示。

第一个,将output.hashFunction更改为使用“xxhash64”,抱怨缺少摘要方法。

错误:不支持摘要方法

设置 Experiments.futureDefaults = true 会出现此错误:

类型错误:无法设置未定义的属性(设置“futureDefaults”)

如果有人可以帮助我理解为什么它不起作用,以及是否可以采取任何措施来使用替代哈希算法,我将不胜感激。

谢谢。

const createExpoWebpackConfigAsync = require('@expo/webpack-config');

module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);

  // Customize the config before returning it.
  config.output.hashFunction = 'xxhash64';
  config.experiments.futureDefaults = true;
  return config;
};
Run Code Online (Sandbox Code Playgroud)

小智 9

如果这不起作用,您可以编辑webpack-config.js并使用您选择的哈希函数添加这些行:

const crypto = require("crypto");
const crypto_orig_createHash = crypto.createHash;
crypto.createHash = algorithm => crypto_orig_createHash(algorithm == "md4" ? "sha256" : algorithm);
Run Code Online (Sandbox Code Playgroud)

当需要恢复到旧算法(OpenSSL /可能不太安全的算法)以暂时解决任何兼容性问题时很有用。

来源:https ://stackoverflow.com/a/69691525/3426192


Olu*_*ule 3

为您的 Node.js 运行时安装xxhash-addon

其类的实现满足Webpack 所需的XXHash64自定义接口要求(对象必须具有更新/摘要方法) 。hashFunction

const createExpoWebpackConfigAsync = require('@expo/webpack-config');

module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);

  // Customize the config before returning it.
  config.output.hashFunction = require('xxhash-addon').XXHash64;
  return config;
};
Run Code Online (Sandbox Code Playgroud)