[英]Exporting from one library if web, another library if native in React Native
所以我正在嘗試使用勝利圖表( https://formidable.com/open-source/victory )並且不希望只使用 webview,因為他們有一個本機實現。
但是,我正在嘗試將庫與 React Native Web 一起使用,但它根本不起作用,我收到以下錯誤:
/Users/myname/Desktop/Projects/myproject/Frontend/Expo/node_modules/victory-native/lib/components/victory-axis.js 10:22
Module parse failed: Unexpected token (10:22)
You may need an appropriate loader to handle this file type.
|
| export default class extends VictoryAxis {
> static defaultProps = Object.assign({}, VictoryAxis.defaultProps, {
| axisComponent: <LineSegment/>,
| axisLabelComponent: <VictoryLabel/>,
我的猜測是我需要使用兩個“包裝”文件,Victory.js 和 Victory.web.js 進行導入。
到目前為止,這是我的 Victory.web.js 文件:
Victory = require('victory');
export default Victory;
這不起作用。
我也試過:
import { VictoryPie } from 'victory';
export VictoryPie;
這給了我錯誤:
/Users/myname/Desktop/Projects/myproject/Frontend/Expo/src/components/utility/Victory.web.js
SyntaxError: /Users/myname/Desktop/Projects/myproject/Frontend/Expo/src/components/utility/Victory.web.js: Unexpected token (3:17)
1 | import { VictoryPie } from 'victory';
2 |
> 3 | export VictoryPie;
我只想能夠在 React Native 和 React Native Web 上使用這個庫而不會引發錯誤。 有什么辦法嗎?
不確定這是否是最好的方法,但這種方法對我有用:
export const VictoryPie = require('victory').VictoryPie;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.