Skip to content

Commit

Permalink
Simplify Webpack instructions on cMaps and standard fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jul 21, 2023
1 parent db43c90 commit 38f3d38
Showing 1 changed file with 32 additions and 40 deletions.
72 changes: 32 additions & 40 deletions README.md
Expand Up @@ -236,30 +236,26 @@ First, you need to copy cMaps from `pdfjs-dist` (React-PDF's dependency - it sho

##### Webpack

Add `copy-webpack-plugin` to your project if you haven't already:
Add `copy-webpack-plugin` by executing `npm install copy-webpack-plugin --save-dev` or `yarn add copy-webpack-plugin --dev` and add the following to your Webpack config:

```
npm install copy-webpack-plugin --save-dev
```

Now, in your Webpack config, import the plugin:

```ts
import path from 'node:path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
```
```diff
+import path from 'node:path';
+import CopyWebpackPlugin from 'copy-webpack-plugin';

and in `plugins` section of your config, add the following:
+const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps');

```ts
new CopyWebpackPlugin({
patterns: [
{
from: path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'),
to: 'cmaps/'
},
module.exports = {
plugins: [
+ new CopyWebpackPlugin({
+ patterns: [
+ {
+ from: cMapsDir,
+ to: 'cmaps/'
+ },
+ ],
+ }),
],
}),
};
```

##### Other tools
Expand Down Expand Up @@ -327,30 +323,26 @@ First, you need to copy standard fonts from `pdfjs-dist` (React-PDF's dependency

##### Webpack

Add `copy-webpack-plugin` to your project if you haven't already:
Add `copy-webpack-plugin` by executing `npm install copy-webpack-plugin --save-dev` or `yarn add copy-webpack-plugin --dev` and add the following to your Webpack config:

```
npm install copy-webpack-plugin --save-dev
```

Now, in your Webpack config, import the plugin:

```ts
import path from 'node:path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
```
```diff
+import path from 'node:path';
+import CopyWebpackPlugin from 'copy-webpack-plugin';

and in `plugins` section of your config, add the following:
+const standardFontsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts');

```ts
new CopyWebpackPlugin({
patterns: [
{
from: path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts'),
to: 'standard_fonts/'
},
module.exports = {
plugins: [
+ new CopyWebpackPlugin({
+ patterns: [
+ {
+ from: standardFontsDir,
+ to: 'standard_fonts/'
+ },
+ ],
+ }),
],
}),
};
```

##### Other tools
Expand Down

0 comments on commit 38f3d38

Please sign in to comment.