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: provide migration guide #282

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ const sidebar = {
},
],
},
{
text: 'Migration from faker.js v5',
link: '/migration/',
},
],
};

Expand Down
53 changes: 53 additions & 0 deletions docs/migration/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Migration from faker.js v5

There are now two bundles: `cjs` and `esm`

The browser bundle was dropped in favor of `esm`

So if you like to use `Faker` in the **browser**, just use:

```html
<script type="module">
import { faker } from 'https://unpkg.com/@faker-js/faker';

console.log(`${faker.name.firstName()} ${faker.name.lastName()}`);
</script>
```

A stackblitz playground can be found here: https://stackblitz.com/edit/typescript-damv7h

:::tip
Faker now provides TypeScript types out of the box.
So you can remove `@types/faker` completely.
:::

You no longer need to import `faker` as a standard import, but as a tree shakeable instance.

For JS:

```js
const { faker } = require('@faker-js/faker');

// Or specific locale
const fakerDe = require('@faker-js/faker/locale/de');
```

For TS:

```ts
import { faker } from '@faker-js/faker';

// Or specific locale
import fakerDe from '@faker-js/faker/locale/de';
```

:::tip
If you have many files using these imports, we suggest to use e.g. VSCode's search and replace functionality.
:::

---

:::warning
You need to switch from the package `faker` to `@faker-js/faker`.
We also provided all historical versions under the new organization scope. So if you depend on a specific version you still can use `"@faker-js/faker": "5.5.3"`.
:::