gpt4 book ai didi

react-native - 如何使 native 打包程序忽略某些目录

转载 作者:行者123 更新时间:2023-12-03 14:47:28 29 4
gpt4 key购买 nike

问题:

我的项目有一个 @providesModule naming collision尝试运行时 react-native run-ios从命令行。它与自动生成的目录冲突 dist/它是由另一个 npm 包 esdoc 创建的。我希望能够保留这个自动生成的目录,并让 react native 打包程序忽略 dist/目录

错误信息:

[01/23/2017, 13:17:07] <START> Building Haste Map
Failed to build DependencyGraph: @providesModule naming collision:
Duplicate module name: ann
Paths: /Users/thurt/projects/example/package.json collides with /Users/thurt/projects/example/dist/esdoc/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
Error: @providesModule naming collision:
Duplicate module name: ann
Paths: /Users/thurt/projects/example/package.json collides with /Users/thurt/projects/example/dist/esdoc/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
at HasteMap._updateHasteMap (/Users/thurt/projects/example/node_modules/react-native/packager/react-packager/src/node-haste/DependencyGraph/HasteMap.js:158:13)
at p.getName.then.name (/Users/thurt/projects/example/node_modules/react-native/packager/react-packager/src/node-haste/DependencyGraph/HasteMap.js:133:31)

最佳答案

此配置有在 RN 版本之间更改的习惯。有关创建配置文件、加载配置文件和清除缓存的特定版本说明,请参见下文。
对于 React Native >= 0.64(?)
这是推测性的,因为 0.64 尚未发布,but a rename from blacklist to exclusionList made in metro 0.60due to land在 RN 中 0.64。
在您的项目根目录中创建 metro.config.js内容:

const exclusionList = require('metro-config/src/defaults/exclusionList');

// exclusionList is a function that takes an array of regexes and combines
// them with the default exclusions to return a single regex.

module.exports = {
resolver: {
blacklistRE: exclusionList([/dist\/.*/])
}
};
对于 React Native >= 0.59, < 0.64
在您的项目根目录中创建 metro.config.js内容:
const blacklist = require('metro-config/src/defaults/blacklist');

// blacklist is a function that takes an array of regexes and combines
// them with the default blacklist to return a single regex.

module.exports = {
resolver: {
blacklistRE: blacklist([/dist\/.*/])
}
};
对于 React Native >= 0.57, < 0.59
在您的项目根目录中创建 rn-cli.config.js内容:
const blacklist = require('metro-config/src/defaults/blacklist');

// blacklist is a function that takes an array of regexes and combines
// them with the default blacklist to return a single regex.

module.exports = {
resolver: {
blacklistRE: blacklist([/dist\/.*/])
}
};
对于 React Native >= 0.52, < 0.57
在您的项目根目录中创建 rn-cli.config.js内容:
const blacklist = require('metro').createBlacklist;

module.exports = {
getBlacklistRE: function() {
return blacklist([/dist\/.*/]);
}
};
对于 React Native >= 0.46, < 0.52 .
在您的项目根目录中创建 rn-cli.config.js内容:
const blacklist = require('metro-bundler').createBlacklist;

module.exports = {
getBlacklistRE: function() {
return blacklist([/dist\/.*/]);
}
};
对于 React Native < 0.46 .
在您的项目根目录中创建 rn-cli.config.js内容:
const blacklist = require('react-native/packager/blacklist');

module.exports = {
getBlacklistRE: function() {
return blacklist([/dist\/.*/]);
}
};
所有版本 < 0.59
通过传递 --config 让您的 CLI 命令使用此配置选项: react-native run-ios --config=rn-cli.config.js(配置文件应该由 RN >= 0.59 自动获取,因为它被重命名为 metro.config.js )
所有版本:缓存注意事项
请注意,您的黑名单项目可能已被打包程序包含在缓存中,在这种情况下,第一次使用黑名单运行打包程序时,您可能需要使用 --reset-cache 重置缓存。

关于react-native - 如何使 native 打包程序忽略某些目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41813211/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com