Skip to content

Commit

Permalink
Add Webpack 5 specific entry, update README, update Webpack 2 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 19, 2022
1 parent a2bd52b commit 6d53c89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ Check the [sample directory](https://github.com/wojtekmaj/react-pdf/tree/main/sa

It is crucial for performance to use PDF.js worker whenever possible. This ensures that PDF files will be rendered in a separate thread without affecting page performance. To make things a little easier, we've prepared several entry points you can use.

#### Webpack
#### Webpack ≤ 4

Instead of directly importing modules you need from `'react-pdf'`, import them like so:

```js
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
```

#### Webpack 5

Instead of directly importing modules you need from `'react-pdf'`, import them like so:

```js
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack5';
```

#### Parcel 1

Instead of directly importing modules you need from `'react-pdf'`, import them like so:
Expand Down
2 changes: 1 addition & 1 deletion sample/webpack5/Sample.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack5';
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';

import './Sample.less';
Expand Down
18 changes: 18 additions & 0 deletions src/entry.webpack5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as pdfjs from 'pdfjs-dist/legacy/build/pdf';

import Document from './Document';
import Outline from './Outline';
import Page from './Page';

import { displayWorkerWarning } from './shared/utils';

displayWorkerWarning();

pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/legacy/build/pdf.worker', import.meta.url);

export {
pdfjs,
Document,
Outline,
Page,
};

0 comments on commit 6d53c89

Please sign in to comment.