我已经使用react-native
and设置了 monorepo 项目react-native-web
。我正在为 Android、iOS 和 Web 共享相同的代码库。安装 react-native-vector-icons 后,我在所有三个平台上都运行了代码,它在 Android 和 iOS 中运行良好,但在 Web 中却不行。在网络中,它如下所示:
我已经Webpack
按照这里的描述进行了设置
下面是我的Webpack
配置config-overrides.js
:
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
// our packages that will now be included in the CRA build step
const appIncludes = [
resolveApp('src'),
resolveApp('../components/src'),
];
//below is the config for react-native-vector-icons
const ttf = {
test: /\.ttf$/,
loader: "file-loader",
include: path.resolve(__dirname, "../../node_modules/react-native-vector-icons"),
};
module.exports = function override(config, env) {
// allow importing from outside of src folder
config.resolve.plugins = config.resolve.plugins.filter(
plugin => plugin.constructor.name !== 'ModuleScopePlugin'
);
config.module.rules[0].include = appIncludes;
config.module.rules[1] = ttf; //add the react-native-vector-icons here
config.module.rules[2].oneOf[1].include = appIncludes;
config.module.rules[2].oneOf[1].options.plugins = [
require.resolve('babel-plugin-react-native-web'),
].concat(config.module.rules[2].oneOf[1].options.plugins);
config.module.rules = config.module.rules.filter(Boolean);
config.plugins.push(
new webpack.DefinePlugin({__DEV__: env !== 'production'})
);
return config
};
下面是react-native-vector-icons
在我的App.js
文件中使用
import Icon from 'react-native-vector-icons/dist/FontAwesome';
<Icon name="glass" size={24}/>
我不知道为什么图标没有加载或我错过了配置。请帮我。先感谢您。