-
-
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
Investigate why importing anything from '@faker-js/faker' directly causes all of faker to be bundled. #1791
Comments
So to explain what a side effect is: When a function modifies the state of something outside its scope, then it is declared as a side effect For example: faker/src/modules/helpers/unique.ts Line 144 in 64f480d
faker/src/modules/helpers/unique.ts Line 104 in 64f480d
faker/src/modules/helpers/unique.ts Line 9 in 64f480d
The I'm not aware of any other side effects right now |
Would moving this to a class field fix that issue? |
Team Decision We will try to investigate this for v8.0
|
@xDivisionByZerox pointed made a hint in meeting 2023-04-20 that we could move the variable Line 41 in bf67a21
This should be tested and could work, so that when loading the file, no variable assignment will be made in src/index.ts itself, but only in the underlying file on demand |
@evanw could you help us with this bug? Please checkout git clone git@github.com:faker-js/faker.git
cd faker
pnpm install
pnpm run build
cd ..
git clone git@github.com:faker-js/playground.git
cd playground
git switch next
pnpm install
cd playgrounds/vite-cjs
pnpm run compile # 3759.57 KiB / gzip: 995.54 KiB Open - faker.image.urlLoremFlickr({ category: "nature" }) + new FakerError("test")
+ faker.image.urlLoremFlickr({ category: "nature" }) + new Error("test") run |
Moving this into Milestone v8 as we have decided that it is not blocking a release v8.0 |
I just realised that faker is taking 3.6MB after build in React... |
Thats why we explicitly ask you to install our library as a Dev Dependency: https://fakerjs.dev/guide/#installation
There is also additional hints about this in the Usage Guide for the Browser: https://fakerjs.dev/guide/usage.html#browser
|
Faker version 5 is totally fine on the browser. |
You can also import a specific locale to avoid the bug. import { faker } from '@faker-js/faker/locale/de'; https://fakerjs.dev/guide/localization.html#individual-localized-packages |
It is super heavy. |
Clear and concise description of the problem
Importing anything directly from
@faker-js/faker
causes the bundler to contain all of faker in the resulting bundle.Reproduction:
https://github.com/faker-js/playground/blob/main/playgrounds/vite-cjs/src/App.vue
Add:
That will increase the bundle size from 0.6MB to 3.6MB.
Maybe try with sideEffect: false + refactorings.
Alternative
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: