-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrollup.config.js
112 lines (110 loc) · 2.81 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import copy from 'rollup-plugin-copy';
import ignore from 'rollup-plugin-ignore';
/**
* # Rollup configuration
*
* ### pdf.js
*
* - Transform UMD to ESM
* - Resolve commonJS imports, **except**:
* - Ignore `pdf.worker.js` import. This is very important, as it's conditionally required and is very large in size.
* - Copy over all remaining files we wish to provide.
*
* With `pdf.worker.js` ignored, pdfjs will expect a link to the file externally (see above)
*
* ### pdf_viewer.js
*
* - Transform UMD to ESM
* - Resolve imports
* - Ignore `pdf.js`. This is important, as we don't want to serve duplicates of pdfjs.
*
* With `pdf.js` ignored, the viewer will expect to find a global pdfjs. This is circumvented by temporarily adding pdfjs to the global scope,
* and removed immediately after the viewer acquires a reference.
*/
export default [
{
input: './src/core/pdf.cjs',
output: {
file: './build/pdf.js',
format: 'es',
},
plugins: [
ignore(['./pdf.worker.js']),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
copy({
targets: [
// the worker is used directly as-is
{
src: './node_modules/pdfjs-dist/build/pdf.worker.js',
dest: './build/',
},
{
src: './node_modules/pdfjs-dist/build/pdf.worker.min.js',
dest: './build/',
},
{
src: './node_modules/pdfjs-dist/build/pdf.worker.entry.js',
dest: './build/',
},
{
src: './node_modules/pdfjs-dist/build/pdf.worker.js.map',
dest: './build/',
},
{
src: './node_modules/pdfjs-dist/LICENSE',
dest: './',
},
// vend typings
{
src: './src/pdf.d.ts',
dest: './build/',
},
{
src: './node_modules/pdfjs-dist/types/',
dest: './',
},
],
}),
nodePolyfills(),
],
},
{
input: './src/viewer/module.cjs',
output: {
file: './web/module.js',
format: 'es',
},
plugins: [
ignore(['../build/pdf.js']),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
copy({
targets: [
{
src: './src/viewer/pdf_viewer.js',
dest: './web/',
},
{
src: './src/viewer/util.js',
dest: './web/',
},
{
src: './src/pdf_viewer.d.ts',
dest: './web/',
},
],
}),
nodePolyfills(),
],
},
];