Skip to content

Commit 38f3d38

Browse files
committed
Simplify Webpack instructions on cMaps and standard fonts
1 parent db43c90 commit 38f3d38

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

README.md

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -236,30 +236,26 @@ First, you need to copy cMaps from `pdfjs-dist` (React-PDF's dependency - it sho
236236

237237
##### Webpack
238238

239-
Add `copy-webpack-plugin` to your project if you haven't already:
239+
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:
240240

241-
```
242-
npm install copy-webpack-plugin --save-dev
243-
```
244-
245-
Now, in your Webpack config, import the plugin:
246-
247-
```ts
248-
import path from 'node:path';
249-
import CopyWebpackPlugin from 'copy-webpack-plugin';
250-
```
241+
```diff
242+
+import path from 'node:path';
243+
+import CopyWebpackPlugin from 'copy-webpack-plugin';
251244

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

254-
```ts
255-
new CopyWebpackPlugin({
256-
patterns: [
257-
{
258-
from: path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'),
259-
to: 'cmaps/'
260-
},
247+
module.exports = {
248+
plugins: [
249+
+ new CopyWebpackPlugin({
250+
+ patterns: [
251+
+ {
252+
+ from: cMapsDir,
253+
+ to: 'cmaps/'
254+
+ },
255+
+ ],
256+
+ }),
261257
],
262-
}),
258+
};
263259
```
264260

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

328324
##### Webpack
329325

330-
Add `copy-webpack-plugin` to your project if you haven't already:
326+
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:
331327

332-
```
333-
npm install copy-webpack-plugin --save-dev
334-
```
335-
336-
Now, in your Webpack config, import the plugin:
337-
338-
```ts
339-
import path from 'node:path';
340-
import CopyWebpackPlugin from 'copy-webpack-plugin';
341-
```
328+
```diff
329+
+import path from 'node:path';
330+
+import CopyWebpackPlugin from 'copy-webpack-plugin';
342331

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

345-
```ts
346-
new CopyWebpackPlugin({
347-
patterns: [
348-
{
349-
from: path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts'),
350-
to: 'standard_fonts/'
351-
},
334+
module.exports = {
335+
plugins: [
336+
+ new CopyWebpackPlugin({
337+
+ patterns: [
338+
+ {
339+
+ from: standardFontsDir,
340+
+ to: 'standard_fonts/'
341+
+ },
342+
+ ],
343+
+ }),
352344
],
353-
}),
345+
};
354346
```
355347

356348
##### Other tools

0 commit comments

Comments
 (0)