問題描述
如何在 Expo 應用示例嵌套文件夾中熱重載開發包? (How to hot reload a development package in an Expo app example nested folder?)
Expo 應用程序示例是否可以加載位於父文件夾中的模塊並在我重建包時查看示例應用程序中的更改(使用 tsc ‑w 重建任何保存的文件)?我確切地說該模塊尚未在 npm 上發布。
我已經成功地使用帶有 yarn 工作空間和 expo‑yarn‑workspaces 包的 monorepo 架構來做到這一點。但是當你不想像 monorepo 那樣發布你的包的情況下呢?
例如,在這個 repo https://github.com/cuvent/react‑native‑vision‑camera 在裸工作流中有一個示例 RN 應用程序,在其 package.json 中有沒有提到開發的包(意思是它' s 沒有像正常的依賴項一樣安裝)。但是在應用程序 src/App.tsx 中,該包的使用方式如下:
import { Camera, frameRateIncluded, sortFormatsByResolution, filterFormatsByAspectRatio } from 'react‑native‑vision‑camera';
雖然,react‑native‑vision‑camera 的使用就像它已經並且通常與 yarn 或 npm 一起安裝一樣。它是如何工作的?
謝謝。
參考解法
方法 1:
Finally, I've found something that works for me. You can find my config for metro if you want here: https://github.com/grean/react‑native‑metro‑config‑app‑example With it, you can access the parent component from the expo app, modify it and immediately see the hot‑reload changes. Create a file metro.config file in your expo root app directory with that code inside:
let config = require('@grean/react‑native‑metro‑config‑app‑example/index.js');
module.exports = config
For a whole example, you can check this repo out: https://github.com/grean/react‑native‑scale‑text
(by Guillaume Réan、Guillaume Réan)