-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
c: featureRequest for new featureRequest for new featurep: 1-normalNothing urgentNothing urgents: acceptedAccepted feature / Confirmed bugAccepted feature / Confirmed bug
Milestone
Description
Clear and concise description of the problem
When using the package, even if you only ever needed 1 specific function you have to import the entire thing into your project in order to use it, which leaves it at the mercy of tree-shaking (assuming you're bundling the project that makes use of faker, which I'd assume is most use-cases).
Suggested solution
Instead of exporting everything under the to-level faker class, instead export each API module separately to allow only importing the things that are actually being used
// Current way to import, meaning we have to hope that the specific
// bundler being used (rollup, webpack, esbuild, etc) tree-shakes everything else away
import { faker } from '@faker-js/faker';
const noun = faker.word.noun();vs
// Proposed solution, guarantees that at most the only thing that is
// bundled in is all the underlying functions for the "word" module
import { word } from '@faker-js/faker';
const noun = word.noun();Alternative
The APIs could be exported alongside the main export, which would remov th breaking change
import { faker, word } from '@faker-js/faker';Or the APIs could be exported in their own nested namespace (the same as locales are, though that may make locales funky)
import { faker } from '@faker-js/faker';
import { word } from '@faker-js/faker/word';
import { address } from '@faker-js/faker/locale/de/word';Additional context
No response
joshsalverda, ShivamJoker, sgpinkus, lynchem, heathdutton and 2 more
Metadata
Metadata
Assignees
Labels
c: featureRequest for new featureRequest for new featurep: 1-normalNothing urgentNothing urgents: acceptedAccepted feature / Confirmed bugAccepted feature / Confirmed bug