byCedric / expo-monorepo-example

Fast pnpm monorepo for cross-platform apps built with Expo / React Native and React.
https://docs.expo.dev/guides/monorepos/
MIT License
724 stars 76 forks source link

Problem bundling with assets on android if located in package #68

Open johkade opened 2 years ago

johkade commented 2 years ago

Topic and scope of discussion

When placing assets (e.g. PNGs) in a package folder, they don't seem to be bundled correctly on android and are not displayed. iOS and web work flawlessly.

Motivation

If an asset belongs to a feature, I would like to co-locate it with that feature. And not have to place it in both of the apps as a duplicate, if possible.

Additional context

Even though the app.json specifies **/* as a path to bundle assets, android doesn't show anything where the image should be. iOS and web work without any troubles after a rebuild. Throwing the assets into expo/assets works on all three platforms.

It would be great to hear, what the preferred approach for shared assets is with this monorepo-example 🤩

Thanks a lot for any input in advance!

byCedric commented 2 years ago

This is a good question, I'd have to dig a bit deeper into what the best way would be. I'll add an internal task to document this on docs.expo.dev too.

For now, I think it's good to mention a slight behavior change in the classic builds and EAS build (or building it yourself).

  1. assetBundlePatterns was mostly intended to auto-bundle certain assets, even if they aren't imported (dynamically importing - require(\./asset/${dynamic}.png`)` - assets is also not detectable, hence this was created).
  2. With EAS build or building it yourself, any asset file imported through JS (e.g. import './assets/my-image.png') is bundled automatically.

That being said, you should be able to add assets in a workspace package and import it. E.g. with: