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: rewrite tree-shaking part #549

Merged
merged 4 commits into from
Mar 1, 2022
Merged

Conversation

Shinigami92
Copy link
Member

@Shinigami92 Shinigami92 added the c: docs Improvements or additions to documentation label Feb 23, 2022
@Shinigami92 Shinigami92 self-assigned this Feb 23, 2022
@Shinigami92 Shinigami92 marked this pull request as ready for review February 23, 2022 13:32
@Shinigami92 Shinigami92 requested review from ST-DDT and a team February 23, 2022 13:32
@codecov
Copy link

codecov bot commented Feb 23, 2022

Codecov Report

Merging #549 (b24b0be) into main (4eef328) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #549   +/-   ##
=======================================
  Coverage   99.34%   99.34%           
=======================================
  Files        1920     1920           
  Lines      176368   176368           
  Branches      904      906    +2     
=======================================
+ Hits       175211   175213    +2     
+ Misses       1101     1099    -2     
  Partials       56       56           
Impacted Files Coverage Δ
src/vendor/unique.ts 97.58% <0.00%> (+1.61%) ⬆️

@JessicaSachs
Copy link
Contributor

Content is good. Needs some rephrasing. Will check it out in a bit.

@ST-DDT ST-DDT linked an issue Feb 23, 2022 that may be closed by this pull request
@JessicaSachs
Copy link
Contributor

I'm following the instructions above. Do you expect

import { faker } from '@faker-js/faker

to be tree-shaken? I wrote this in my other comment, but nothing is tree-shakeable right now.

Steps to reproduce:

# clone faker
npm init vite
# (say yes to everything)
cd vite-project
pnpm install
cd ..
pnpm link --dir ./vite-project

Modify the JS to import faker.

// within main.js
import { faker } from '@faker-js/faker'
console.log(faker.locales) // shows all locales

Build and preview the dist for vite

pnpm vite build # See that the gzipped version is 678kb, should be ~200ish kb

If you modify the import to const fakerEn = require('@faker-js/faker/locale/en'), it's still not tree shaken and the bundle is ~600kb, even though faker.locales only shows that en is loaded.

We need to rewrite the docs to say that tree-shaking isn't supported right now, or we need to change the way we export the Faker class.

@Shinigami92
Copy link
Member Author

@JessicaSachs 600kb seems really accurate, we really have that much for the english locales.
So using @faker-js/faker/locale/en "only" loads these english locales + the faker instance.
When using the full faker instance, it loads all locales that results in ~7mb ⚠️

@Shinigami92
Copy link
Member Author

@JessicaSachs #548 will solve the tree-shaking problem for locale imports

@Shinigami92
Copy link
Member Author

@JessicaSachs could you have a new look into this? Now that #548 is merged?

@ST-DDT ST-DDT mentioned this pull request Feb 24, 2022
5 tasks
@Shinigami92
Copy link
Member Author

Not sure how to proceed here and no response yet from @JessicaSachs 🤔
I think it's better then the current live documentation. So if we want to change something, we can open a commit in the future anyways 🤷

@JessicaSachs
Copy link
Contributor

JessicaSachs commented Mar 1, 2022

This is good! I'm sorry I hadn't checked back in. Some wording can be improved but it is good as-is.

@ST-DDT ST-DDT merged commit 0afdf03 into main Mar 1, 2022
@ST-DDT ST-DDT deleted the docs-rewrite-tree-shaking-migration branch March 1, 2022 16:16
demipel8 pushed a commit to demipel8/faker that referenced this pull request Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tree-shaking not properly documented
3 participants