Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(babel): minify typeof window (#27530)
# Why It's common to use `typeof window === 'undefined'` to conditionally enable/disable code for server/client environments. `babel-preset-expo` automatically transforms `typeof window === 'undefined` to `true` when bundling for server environments, and `false` when bundling for websites. The check is left as-is when bundling for native client environments to support apps that polyfill `window`. This transform is run in both development and production, but only removes conditional requires in production. You can configure `babel-preset-expo` to skip the transform by passing `{ preserveTypeofWindow: false }`. # How Add `babel-plugin-transform-define` and conditionally enable when bundling for websites and server code. Skip entirely for native client bundles as these are ambiguous. We also expose the ability to force the flag on/off for native client in case users want a more strict runtime protection against `typeof window`. Additionally, I merged `process.env.EXPO_OS` and BASE_URL in this transform to reduce passes. In a follow up PR, I'll merge `process.env.NODE_ENV` and `__DEV__` too. # Test Plan - Added a bunch of babel tests for this functionality. # 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 `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com> Co-authored-by: Aman Mittal <amandeepmittal@live.com>
- Loading branch information
1 parent
c9a3adf
commit bc51c52
Showing
12 changed files
with
419 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.