-
-
Notifications
You must be signed in to change notification settings - Fork 975
Tree-shaking not properly documented #405
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
Comments
This feature was supposedly added in #152 |
This will and should reduce the loaded size to only the needed locale. Something like |
Or does it only refer to per language shaking? import fakerDe from "@faker-js/faker/locale/de";
console.log("a", fakerDe.name.jobType()); // Orchestrator |
We should be more explicit about the treeshaking behavior/limitations in our docs to avoid any confusion about this in the future. The documentation should be updated to contain:
|
Well I DID use Also: yes, proper treeshaking isn't that easy but also isn't that hard. separating the different faker modules would already help a lot. Ofc, the premium would be to only import the actual functions you need e.g. |
@Fuzzyma Please try to use |
Probably because we link a few more entries now that existed in the sources but where never added to the translation tree.
Yes. Lines 150 to 152 in 773bcec
EDIT: @Shinigami92 is always a few seconds faster... |
This needs to be in the v6.0 release version, to avoid confusion and frustration when switching to this lib. |
Before I started writing documentation, I wanted to make sure I was giving the right guidance on how to import things performantly. To make sure I was getting it right, I started using So I started digging into why the bundle was including all locales. If you turn minification off and trace through the imports, you'll see that I started making some changes to test out my theory and we should be getting around ~207.64 kB compressed + minified if only english is loaded. I'll continue exploring this, but making changes is a bit difficult because of how much codegen is being done on the locales and the way they're exported. |
I will have a look into this init_src later, but let's remove documentation about tree-shaking for now and address it later in a future milestone. |
Maybe we have to move the Faker class to its own file. That way we don't have to import the index.ts file which contains the faker instance with all locales. |
As we wanted to do this anyways, I will open a PR for that now. But I'm not sure if this really will work 🤔 |
Rewrite docs for tree-shaking: #549 |
Describe the bug
Following the guide on the website, you just have to
import { faker } from '@faker-js/faker';
. That doesn't work. It actually makes it worse by adding a whopping 1/2MB to the bundle size.The section above says, that you should only import what you need. Well I tried that as well:
So is this is supposed to work? Looking at the code, I can see why this is not treeshakeable. But why is it advertized?
Reproduction
I am using vite. So bundling is done by rollup. Using faker anywhere leads to the whole faker lib in your bundle
Additional Info
No response
The text was updated successfully, but these errors were encountered: