Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Keeping the bundle size small in bare apps with exclude #9736

Closed
etaiklein opened this issue Aug 13, 2020 · 1 comment
Closed

[docs] Keeping the bundle size small in bare apps with exclude #9736

etaiklein opened this issue Aug 13, 2020 · 1 comment

Comments

@etaiklein
Copy link

Improvement for https://docs.expo.io/bare/installing-unimodules/ (or maybe a new page in /bare relating to app performance?)

see https://forums.expo.io/t/unimodules-what-else-can-i-exclude/41079/3

I would like to avoid integrating with unnecessary modules and bloating my app. Since there is only a denyList exclude option and not an allowList include option- how can I get the full list of excludable modules?

Also, modules excluded in native integrations are still unnecessarily downloaded into /node_modules. I would love the documentation to show steps for removing excluded node_modules safely.

Request:
How can I get the full list of excludable modules?
How can I remove excluded modules from node_modules?
Any other tips for keeping the bundle small in the bare workflow.

@brentvatne
Copy link
Member

hi there!

How can I get the full list of excludable modules?

the following pages are added via react-native-unimodules:

"expo-asset": "~8.1.7",
"expo-constants": "~9.1.1",
"expo-file-system": "~9.1.0",
"expo-image-loader": "~1.1.1",
"expo-permissions": "~9.2.0",
"unimodules-app-loader": "~1.2.0",
"unimodules-barcode-scanner-interface": "~5.2.1",
"unimodules-camera-interface": "~5.2.1",
"unimodules-constants-interface": "~5.2.1",
"unimodules-face-detector-interface": "~5.2.1",
"unimodules-file-system-interface": "~5.2.1",
"unimodules-font-interface": "~5.2.1",
"unimodules-image-loader-interface": "~5.2.1",
"unimodules-permissions-interface": "~5.2.1",
"unimodules-sensors-interface": "~5.2.1",
"unimodules-task-manager-interface": "~5.2.1"

first, you don't need to exclude any of the interfaces. they empty js files and one or two header files that allow distinct modules to depend on functionality from other modules by requesting a module that implements an interface. these will have no size or performance impact on your app when it's built.

second, you almost certainly want expo-asset, expo-file-system (required by expo-asset), expo-constants, and expo-permissions. these are used by every app, through apis like Font or Camera or Updates and a variety of other things.

so what's left? if you have the expo package in your project, there are some additional dependencies here:

"expo-asset": "~8.1.7",
"expo-constants": "~9.1.1",
"expo-error-recovery": "~1.2.1",
"expo-file-system": "~9.1.0",
"expo-font": "~8.2.2",
"expo-keep-awake": "~8.2.1",
"expo-linear-gradient": "~8.2.2",
"expo-linking": "~1.0.3",
"expo-location": "~8.3.0",
"expo-permissions": "~9.2.0",
"expo-splash-screen": "^0.5.0",
"expo-sqlite": "~8.3.0",

you may want to remove expo-sqlite, expo-splash-screen (although i'd recommend keeping it), expo-location, and expo-linear-gradient. up to you.

How can I remove excluded modules from node_modules?

the only impact this will have is on your npm install time, js from packages that aren't used in your app will not be included in you final bundle. you can see this with https://github.com/IjzerenHein/react-native-bundle-visualizer

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Sep 21, 2020
Done to reduce boring mocks (in particular, remove boring mocks for
things from Expo) in our Jest setup.

A redo of 62621ef and e40c020, reverted in 347aa96, which we
can do following the recent RN upgrade to v0.62 (see 347aa96 for
details).

Since we're on react@16.11.0, use 16.11.0 as the version range for
react-dom, instead of 16.9.0 as we did in 62621ef. (We don't use
any code in react-dom, but we unfortunately have to include it to
satisfy peer dependencies; see 62621ef.)

This time around, we get a peer-dependency warning suggesting we
need to install expo-splash-screen:

"""
warning "jest-expo > @expo/config >
@expo/configure-splash-screen@0.1.17" has unmet peer dependency
"expo-splash-screen@*".
"""

So, do that. It really should go under `devDependencies`, since we
only need it for jest-expo. But I find that react-native-unimodules
is automatically linking `expo-splash-screen`'s native code on iOS
and Android, whether it's in `devDependencies` or `dependencies`.
Although I didn't encounter problems building and running for
release on iOS or Android with this in `devDependencies`, it seems
problematic to link native code from a package we've said is for
development only. So, reluctantly, say that it's not for development
only. We may in fact want to use it in production one day; if we do,
we'll probably need to put together a Flow libdef.

[1] We can't prevent this from happening in the usual way, by adding
    lines to `react-native.config.js`; it seems Unimodules isn't
    informed by that file, which is where React Native's autolinking
    (a separate process) takes its cues from.

    There may be a way to tell Unimodules to exclude it, but it
    seems to mean calling code in two or three places that's mostly
    meant for internal use; see
    https://forums.expo.io/t/unimodules-what-else-can-i-exclude/41079
    and
    expo/expo#9736 (comment).
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Sep 21, 2020
Done to reduce boring mocks (in particular, remove boring mocks for
things from Expo) in our Jest setup.

A redo of 62621ef and e40c020, reverted in 347aa96, which we
can do following the recent RN upgrade to v0.62 (see 347aa96 for
details).

Since we're on react@16.11.0, use 16.11.0 as the version range for
react-dom, instead of 16.9.0 as we did in 62621ef. (We don't use
any code in react-dom, but we unfortunately have to include it to
satisfy peer dependencies; see 62621ef.)

This time around, we get a peer-dependency warning suggesting we
need to install expo-splash-screen:

"""
warning "jest-expo > @expo/config >
@expo/configure-splash-screen@0.1.17" has unmet peer dependency
"expo-splash-screen@*".
"""

So, do that. It really should go under `devDependencies`, since we
only need it for jest-expo. But I find that react-native-unimodules
is automatically linking `expo-splash-screen`'s native code on iOS
and Android, whether it's in `devDependencies` or `dependencies`.
Although I didn't encounter problems building and running for
release on iOS or Android with it in `devDependencies`, it seems
problematic to link native code from a package we've said is for
development only. So, reluctantly, say that it's not for development
only, by putting it under `dependencies`. We may in fact want to use
it in production one day; if we do, we'll probably need to put
together a Flow libdef.

[1] We can't do the usual thing to prevent it from getting linked,
    adding lines to `react-native.config.js`. It seems Unimodules
    isn't informed by that file, which is where React Native's
    autolinking (a separate process) takes its cues from.

    There may be a way to tell Unimodules to exclude it, but it
    seems to mean calling code in two or three places that's mostly
    meant for internal use; see
    https://forums.expo.io/t/unimodules-what-else-can-i-exclude/41079
    and
    expo/expo#9736 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants