Skip to content

Commit 3242dfc

Browse files
docs: provide migration guide (round 2!) (#301)
Co-authored-by: Shinigami92 <[email protected]>
1 parent 9b3d6b5 commit 3242dfc

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const randomCard = faker.helpers.createCard(); // random contact card containing
5555
### Deno
5656

5757
```js
58-
import { faker } from "https://cdn.skypack.dev/@faker-js/faker";
58+
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
5959

6060
const randomName = faker.name.findName(); // Willie Bahringer
6161
const randomEmail = faker.internet.email(); // [email protected]

docs/.vitepress/config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ const sidebar = {
7979
],
8080
},
8181
{
82-
text: 'Migration from faker.js v5',
83-
link: '/migration/',
82+
text: 'Migrating from Faker v5',
83+
link: '/migration-guide-v5/',
8484
},
8585
],
8686
};

docs/guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Using the browser is great for experimenting 👍. However, due to all of the st
7474
### Deno
7575

7676
```js
77-
import { faker } from "https://cdn.skypack.dev/@faker-js/faker";
77+
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
7878

7979
const randomName = faker.name.findName(); // Willie Bahringer
8080
const randomEmail = faker.internet.email(); // [email protected]

docs/migration-guide-v5/index.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Migrating from Faker v5 to v6
2+
3+
[[toc]]
4+
5+
### ESM Support
6+
7+
**New Format**: We're now ESM compatible! We've dropped the Browser bundle in favor of ESM.
8+
9+
So if you'd like to use `Faker` in the **browser**, simply include it using a [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html).
10+
11+
```html
12+
<script type="module">
13+
import { faker } from 'https://unpkg.com/@faker-js/faker';
14+
15+
console.log(`${faker.name.firstName()} ${faker.name.lastName()}`);
16+
</script>
17+
```
18+
19+
### Remove all references to `faker` from your project. The new package is located at `@faker-js/faker`
20+
21+
:::warning
22+
You **MUST** swap all references from the `faker` package to the new `@faker-js/faker` package.
23+
24+
In addition to releasing all _future_ versions under the `@faker-js/faker` package namespace, we have also provided all _historical_ versions of Faker.
25+
26+
If you depend on a specific version of Faker you still can reference the version directly.
27+
28+
`npm i @faker-js/[email protected] -D` will work just fine 😄.
29+
:::
30+
31+
### TypeScript
32+
33+
:::tip TypeScript Improvements
34+
Faker now ships with its own types! Remove `@types/faker` from your `package.json` to avoid conflicts.
35+
:::
36+
37+
### Tree-shaking
38+
39+
Faker now supports tree-shaking! We highly recommend that you take advantage of your bundler's tree-shaking capabilities and change how you import Faker. This is especially true if you're importing Faker in the browser.
40+
41+
Faker is a giant package made up of many megabytes of strings. Only import what you need.
42+
43+
:::tip
44+
Migrating to the new tree-shakeable syntax should be quick and painless.
45+
:::
46+
47+
For JS:
48+
49+
```js
50+
const { faker } = require('@faker-js/faker');
51+
52+
// Or specific locale
53+
const fakerDe = require('@faker-js/faker/locale/de');
54+
```
55+
56+
For TS:
57+
58+
```ts
59+
import { faker } from '@faker-js/faker';
60+
61+
// Or specific locale
62+
import fakerDe from '@faker-js/faker/locale/de';
63+
```
64+
65+
Please [open an issue on GitHub](https://github.com/faker-js/faker/issues/new?assignees=&labels=pending+triage&template=freestyle.md) if we've missed any steps.
66+
67+
Happy Faking!
68+
69+
- Shini, Jess, and the Faker Team

0 commit comments

Comments
 (0)