| #
57eba0f9 |
| 29-Mar-2023 |
Evan Bacon <[email protected]> |
feat(cli): add node target and externals to Metro (#21886)
# Why
In order to bundle for Node.js targets using Metro (required for React
Server Components and other features), we need to add supp
feat(cli): add node target and externals to Metro (#21886)
# Why
In order to bundle for Node.js targets using Metro (required for React
Server Components and other features), we need to add support for
leaving the Node.js imports in-tact (no first-class support), and the
ability to indicate that we're targeting Node.js without changing the
platform from web.
<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->
# How
- Use `resolver.environment` and `transform.environment` to partially
invalidate the Metro cache and pass custom options to the transformer
(usage currently unimplemented) and resolver.
- Tap Node.js files in the user project under
`.expo/metro/externals/[module]/index.js` and redirect requests to these
modules when bundling for Node.js environments.
- Tap a polyfill which exposes `$$require_external` on the global.
`$$require_external` can be used to access the environment require from
anywhere in the bundle.
- `$$require_external` asserts when used in the browser or native (where
it shouldn't be available).
<!--
How did you build this feature or fix this bug and why?
-->
# Test Plan
- Added unit tests.
- Tested against an Expo Router project.
<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->
# Checklist
<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->
- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).
---------
Co-authored-by: Expo Bot <[email protected]>
show more ...
|