Native-specific extensions with yarn workspaces and turborepo

70 Views Asked by At

I'm setting up a project with shared packages with turborepo as such:

apps/
├─ app1/ (native)
├─ app2/ (web)

packages/
├─ utils/
│  ├─ storage/
│  │  ├─ index.web.ts
│  │  ├─ index.native.ts
│  ├─ index.ts

Storage here is a storage backend (like browser storage, @react-native-async-storage/async-storage or Expo secure storage). These have various degrees of support in different platforms, and I would like to use Expo secure storage whenever possible.

My goal is to create a set of shared packages with native specific extensions just like it is generally supported by React native projects.

My question is is this possible?

My fallback is to import Platform from react-native (and then use Vite alias for 'react-native': 'react-native-web' in the web projects), and then do the import / branching manually.

But I was wondering if anyone has been able to do this with the tooling available for yarn workspaces / turborepo.

0

There are 0 best solutions below