File tree Expand file tree Collapse file tree 4 files changed +44
-9
lines changed Expand file tree Collapse file tree 4 files changed +44
-9
lines changed Original file line number Diff line number Diff line change 6
6
"plugins" : [
7
7
" @babel/transform-runtime" ,
8
8
" @babel/proposal-class-properties"
9
- ]
9
+ ],
10
+ "env" : {
11
+ "production-esm" : {
12
+ "presets" : [
13
+ [" @babel/env" , { "modules" : false }],
14
+ " @babel/react"
15
+ ],
16
+ "plugins" : [
17
+ [" @babel/transform-runtime" , { "useESModules" : true }],
18
+ " @babel/proposal-class-properties"
19
+ ]
20
+ }
21
+ }
10
22
}
Original file line number Diff line number Diff line change @@ -84,15 +84,23 @@ It is crucial for performance to use PDF.js worker whenever possible. This ensur
84
84
Instead of directly importing/requiring ` 'react-pdf' ` , import it like so:
85
85
86
86
``` js
87
- import { Document } from ' react-pdf/dist/entry.webpack' ;
87
+ // using ES6 modules
88
+ import { Document } from ' react-pdf/dist/esm/entry.webpack' ;
89
+
90
+ // using CommonJS modules
91
+ import { Document } from ' react-pdf/dist/umd/entry.webpack' ;
88
92
```
89
93
90
94
#### Parcel
91
95
92
96
Instead of directly importing/requiring ` 'react-pdf' ` , import it like so:
93
97
94
98
``` js
95
- import { Document } from ' react-pdf/dist/entry.parcel' ;
99
+ // using ES6 modules
100
+ import { Document } from ' react-pdf/dist/esm/entry.parcel' ;
101
+
102
+ // using CommonJS modules
103
+ import { Document } from ' react-pdf/dist/umd/entry.parcel' ;
96
104
```
97
105
98
106
#### Create React App
@@ -115,7 +123,11 @@ pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/$
115
123
If you want to use annotations (e.g. links) in PDFs rendered by React-PDF, then you would need to include stylesheet necessary for annotations to be correctly displayed like so:
116
124
117
125
``` js
118
- import ' react-pdf/dist/Page/AnnotationLayer.css' ;
126
+ // using ES6 modules
127
+ import ' react-pdf/dist/esm/Page/AnnotationLayer.css' ;
128
+
129
+ // using CommonJS modules
130
+ import ' react-pdf/dist/umd/Page/AnnotationLayer.css' ;
119
131
```
120
132
121
133
### Support for non-latin characters
Original file line number Diff line number Diff line change 1
1
const fs = require ( 'fs' ) ;
2
2
3
- fs . copyFile ( 'src/Page/AnnotationLayer.css' , 'dist/Page/AnnotationLayer.css' , ( error ) => {
3
+ fs . copyFile ( 'src/Page/AnnotationLayer.css' , 'dist/esm/ Page/AnnotationLayer.css' , ( error ) => {
4
4
if ( error ) {
5
5
throw error ;
6
6
}
7
7
// eslint-disable-next-line no-console
8
- console . log ( 'AnnotationLayer.css copied successfully.' ) ;
8
+ console . log ( 'AnnotationLayer.css copied successfully to ESM build.' ) ;
9
+ } ) ;
10
+
11
+ fs . copyFile ( 'src/Page/AnnotationLayer.css' , 'dist/umd/Page/AnnotationLayer.css' , ( error ) => {
12
+ if ( error ) {
13
+ throw error ;
14
+ }
15
+ // eslint-disable-next-line no-console
16
+ console . log ( 'AnnotationLayer.css copied successfully to UMD build.' ) ;
9
17
} ) ;
Original file line number Diff line number Diff line change 2
2
"name" : " react-pdf" ,
3
3
"version" : " 4.2.0" ,
4
4
"description" : " Display PDFs in your React app as easily as if they were images." ,
5
- "main" : " dist/entry.js" ,
5
+ "main" : " dist/umd/entry.js" ,
6
+ "module" : " dist/esm/entry.js" ,
6
7
"source" : " src/entry.js" ,
7
8
"scripts" : {
8
- "build" : " yarn build-js && yarn copy-styles" ,
9
- "build-js" : " babel src -d dist --ignore **/*.spec.js,**/*.spec.jsx" ,
9
+ "build" : " yarn build-js-all && yarn copy-styles" ,
10
+ "build-js-all" : " yarn build-js-esm && yarn build-js-umd" ,
11
+ "build-js-esm" : " BABEL_ENV=production-esm babel src -d dist/esm --ignore **/*.spec.js,**/*.spec.jsx" ,
12
+ "build-js-umd" : " BABEL_ENV=production-umd babel src -d dist/umd --ignore **/*.spec.js,**/*.spec.jsx" ,
10
13
"clean" : " rimraf dist" ,
11
14
"copy-styles" : " node ./copy-styles.js" ,
12
15
"jest" : " jest" ,
You can’t perform that action at this time.
0 commit comments