Marking @exp packages as side effects-free for Webpack #4733
Replies: 1 comment 5 replies
-
Firebase packages actually have side-effects, so it would be incorrect to assert them as side-effects free in the package.json. The side effect is used to register services and make them work together. For example, Firestore can talk to Auth without you passing Auth to Firestore explicitly. So it's impossible to code split within the same product (e.g. splitting |
Beta Was this translation helpful? Give feedback.
-
Thanks, team, for your great work on the new
@exp
packages!One particular use case that I've been excited to try is simplified lazy loading of the libs in React apps. The idea is that with the new libs to properly lazy-load them one can safely rely on dynamic imports and components-based or routes-based code-splitting.
Unfortunately that doesn't work out of the box as expected, as webpack cannot do tree-shaking across dynamically imported chunks, as it cannot guarantee correctness due to possible side effects. E.g. this doesn't work:
Both dynamic imports will be bundled in a common chunk.
This also applies to barrel files. Something like that cannot be tree-shaked:
The chunk generated for
otherFile.tsx
will include both functions and firestore, despite only the firestore being used.Webpack allows packages to be marked as side-effects free. Imports from such packages can be tree-shaked even across dynamically imported chunks.
I did test it by marking firebase packages as free of side-effects via a
module.rules
flag. It seems to produce the expected result, at least for barrel files use case.So, the question is - can
@exp
packages be marked as side effects-free? Judging by the new API, that seems reasonable and should result in a better tree-shaking, at least in Webpack.Beta Was this translation helpful? Give feedback.
All reactions