Comments (2)
提示找不到index.js,有什么办法么?
RN 开发模式工作流
在命令行终端中,RN 工程根目录下执行:
$ react-native start
此时 metro 会启动 dev server 将 RN 工程根目录部署到http://localhost:8081
在开发模式下:
- 启动 iOS App时,原生层的代码会请求类似这个地址:
http://localhost:8080/index.js?platform=ios&dev=true
; - 启动 Android App时,原生层的代码会请求类似这个地址:
http://localhost:8080/index.js?platform=android&dev=true
;
metro 接收到上面的请求后,回加載 RN 工程根目录下的 index.js 文件,并开始打包编译。
所以开发模式下会看到 加載进度条,编译完成成功加载后才能看到 UI 视图。
如果 RN 工程根目录下没有 index.js 文件,在启动 App 时,就报错提示:找不到 index.js。
使用 umi-react-native 开发 RN 工作流
每次在命令行终端中,RN 工程根目录下执行:
$ umi g rn
umi-react-native 都会在 RN 工程根目录 下生成 index.js。
此时再启动 metro ,再启动 App 即可正常加載 index.js 文件。
开发模式加載 index.js 文件这个行为是 iOS 和 Android 原生代码中写死的,如果你不想加載 index.js 可以修改原生代码:
from umi-react-native.
可以把业务代码放到src
或者其他目录,但不论如何组织 RN 的工程目录,都必须在根目录下存在一个index.js
文件。
在 RN 工程根目录执行 umi g rn
命令,umi-preset-react-native 会生成 index.js 。
了解详情:命令行工具
from umi-react-native.
Related Issues (10)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umi-react-native.