javascript - 添加反应原生矢量图标以使用反应原生网络反应原生时出错
问题描述
我按照本教程添加react-native-web
到react-native
项目中。但是添加react-native-vector-icons
到项目时出现错误。
./node_modules/react-native-vector-icons/lib/create-icon-set.js
SyntaxError: /home/hamidreza/Desktop/myApp/node_modules/react-native-vector-icons/lib/create-icon-set.js: Support for the experimental syntax 'classProperties' isn't currently enabled (43:22):
41 |
42 | class Icon extends PureComponent {
> 43 | static propTypes = {
| ^
44 | allowFontScaling: PropTypes.bool,
45 | name: IconNamePropType,
46 | size: PropTypes.number,
我也将我的更改babel.config.js
为:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'@babel/plugin-proposal-class-properties',
{
loose: true,
},
],
],
};
或者
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'@babel/plugin-proposal-class-properties'
],
};
但仍有问题。
我应该怎么办?
解决方案
通过添加
path.resolve(appDirectory, 'node_modules/react-native-vector-icons'),
babelLoaderConfiguration
问题解决。
最终web/webpack.config.js
:
const path = require('path');
const webpack = require('webpack');
const appDirectory = path.resolve(__dirname, '../');
const babelLoaderConfiguration = {
test: /\.js$/,
include: [
path.resolve(appDirectory, 'index.web.js'),
path.resolve(appDirectory, 'src'),
path.resolve(appDirectory, 'node_modules/react-native-uncompiled'),
path.resolve(appDirectory, 'node_modules/react-native-vector-icons'),
path.resolve(appDirectory, 'node_modules/react-native-elements'),
],
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['react-native'],
plugins: ['react-native-web'],
},
},
};
const imageLoaderConfiguration = {
test: /\.(gif|jpe?g|png|svg)$/,
use: {
loader: 'url-loader',
options: {
name: '[name].[ext]',
},
},
};
module.exports = {
entry: [path.resolve(appDirectory, 'index.web.js')],
output: {
filename: 'bundle.web.js',
path: path.resolve(appDirectory, 'dist'),
},
module: {
rules: [babelLoaderConfiguration, imageLoaderConfiguration],
},
resolve: {
alias: {
'react-native$': 'react-native-web',
},
extensions: ['.web.js', '.js'],
},
};
推荐阅读
- javascript - 单击时卡片滑块的问题未传递正确的值
- excel - 组合连续数字_Excel公式或VBA
- swift-mt - 如何获取快速消息的发件人?我正在使用 prowide-core 来解析 SWIFT MT (FIN) 消息
- css - 有没有办法实现将一个堆叠上下文的元素堆叠在另一个堆叠上下文的元素之间的视觉效果?
- wordpress - Wordpress 将父类别显示为标题,下方有子项
- javascript - 试图在一系列对象中找到最冷和最热的城市
- java - 注册多个 Jackson 转换器
- c# - 如何在 C# 中将一个表的新旧值保存到另一个表中?
- javascript - 根据参数生成多个文件不能以异步方式工作
- ios - 无法为模拟器构建应用程序