-
-
Notifications
You must be signed in to change notification settings - Fork 929
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
fix: tree-shaking #2790
fix: tree-shaking #2790
Conversation
✅ Deploy Preview for fakerjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #2790 +/- ##
========================================
Coverage 99.95% 99.96%
========================================
Files 2971 2971
Lines 212553 212696 +143
Branches 601 948 +347
========================================
+ Hits 212467 212611 +144
+ Misses 86 85 -1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so weird ...
Theoretically you changed nothing cause export * from './locale';
in index does the same export for allLocales
as before... but it just works magically 🤷
I really don't understand what's going on here
Also I really don't like this sideEffects
key, that is undocumented non-standard webpack introduced, but ecosystem accepted. Why is it not e.g. that it needs to be set to sideEffects: true
explicitly if you have side effects and the default should be false...
However, great work and don't take my ecosystem-rant personally ❤️
This is not even a breaking change, is it? 👀
Ah..., well, IMO we can remove the label, but you already also did not add a |
Haven't done any actual OSS coding in a while + my work does not use conventional commits (so no ! for breaking changes). So I honestly forgot that this is required ^^ I'd still think we should consider this breaking. Just in case. I'll add a migration guide file. |
While it's not breaking, it does mean you no longer need to use the workaround to import one locale right? So we could explain that in the migration guide. |
Can we also remove the "Individual localized packages" section of the Usage docs if this is no longer needed? |
b25100f
Wasn't sure about that, but simpl removed it now. Please check the guide section on the docs preview. I feel like the sections "Custom locales and fallbacks" and "Available lcoales" should be switched now. |
Thanks for fixing this. ❤️ |
Testing it soon, thanks! |
I cant speak for the whole team, but maybe we will do an alpha release today in next 10h 👀 🚀 |
Summary
This PR addresses tree-shaking issues by optimizing the handling of locale imports and exports. The changes ensure that only the necessary locale modules are included in the final bundle, enhancing performance and reducing unnecessary file sizes.
This is a major requirement for the release of v9.0.
Details
The previous implementation was causing unnecessary modules to be included during tree-shaking due to the additional export of the implicit
allLocales
variable.faker/src/index.ts
Line 39 in 03ac471
This was refactored into an explicit export under
./locales/index.ts
. Thegenerate-locales
script has been updated to accommodate this change.Additionally, the package.json file has been updated to specify
"sideEffects": false
, which informs bundlers that all files within this package are side-effect-free and can be safely tree-shaken.To be perfectly honest, even after investigating this issue for multiple hours, I'm still not perfectly sure WHY this exact change fixes the issue.
Please note, that only the combination of these changes will take any action. Applying one or the other change separately does not resolve the issue of everything being included in a final project bundle.
Testing
To verify these changes, follow these steps:
pnpm run build
.package.json
(replace "overrides-for-dev" with "overrides-for-dev").webpack-cjs
andwebpack-esm
.These steps will confirm that the tree-shaking optimizations have reduced the bundle size appropriately and that the library functions as expected with the updated locale handling.
Additional
I consider this a breaking change as of #2335 (comment).
Fixes #1791, #2335.
sideEffects: false
topackage.json
#2335