reactjs - web.js 和 native.js 平台目标在 React Native Web 文件名中不起作用
问题描述
*.web.js
并且*.native.js
平台定位在 React Native Web 文件命名中不起作用。此路径是正确的import { Foo } from './Foo/Foo';
,但它返回以下错误:
Module build failed: Error: ENOENT: no such file or directory
解决方案
目前这方面的文档很少,所以我会全部映射出来。这仅在路径通过src
目录返回时才对我有用,即,而不是在从其他组件导入时../components/Foo/Foo
使用更直接的路径。./Foo/Foo
这是工作文件:
src/components/Foo/Foo.native.js:
import React, { Component } from 'react';
import { View } from 'react-native';
class FooNative extends Component {
render() {
return (
<View></View>
)
}
}
export { FooNative as Foo };
src/components/Foo/Foo.web.js:
import React, { Component } from 'react';
import { View } from 'react-native';
class FooWeb extends Component {
render() {
return (
<View></View>
)
}
}
export { FooWeb as Foo };
src/components/Bar.js:
import React, { Component } from 'react';
import { Foo } from '../components/Foo/Foo';
export default class Bar extends Component {
render() {
return (
<Foo></Foo>
)
}
}
推荐阅读
- android-studio - 为什么每次在 Android Studio 中运行项目时都下载 play-service-base-16.0.0.pom?
- kubernetes - 如何在 Kubernetes 中基于特定路径路由端口
- javascript - 如何在 jQuery Datatable 中获取特定行的唯一 ID 以使用 Laravel 后端删除它
- javascript - 从烧瓶上下文变量中设置 html 按钮激活/停用
- networking - Istio ingress 重写类似于 nginx ingress 的子路径
- java - 使用 RestTemplate 发送 GraphQl 查询
- javascript - 多方 - 与 peerJS 的视频会议
- python - 未找到 Ubuntu 18.04 命令“pyenv”,您的意思是:
- spring-boot - Spring自定义whitelabel错误 - 重定向
- post - POSTMAN - AMAZON MWS - SubmitFeed - 您为供稿传递的 Content-MD5 HTTP 标头不匹配