-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathpdfjs.rollup.config.ts
More file actions
60 lines (58 loc) · 1.94 KB
/
pdfjs.rollup.config.ts
File metadata and controls
60 lines (58 loc) · 1.94 KB
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
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import { defineConfig } from 'rollup'
import esbuild, { minify } from 'rollup-plugin-esbuild'
import { pdfjsTypes } from './src/pdfjs-serverless/rollup/plugins'
const canvasMock = `
new Proxy({}, {
get(target, prop) {
return () => {
throw new Error("@napi-rs/canvas is not available in this environment")
}
},
})
`
.replaceAll('\n', '')
.trim()
export default defineConfig({
input: 'src/pdfjs-serverless/index.mjs',
output: {
file: 'dist/pdfjs.mjs',
format: 'esm',
exports: 'auto',
inlineDynamicImports: true,
generatedCode: {
constBindings: true,
},
sourcemap: false,
},
plugins: [
replace({
delimiters: ['', ''],
preventAssignment: true,
values: {
// Force inlining the PDF.js worker.
'await import(\n /*webpackIgnore: true*/\n /*@vite-ignore*/\n this.workerSrc)': '__pdfjsWorker__',
// Force setting up fake PDF.js worker.
'#isWorkerDisabled = false': '#isWorkerDisabled = true',
// Remove WASM code from the worker.
'wasmExports = await createWasm': 'wasmExports = {}',
'if (!this.#modulePromise)': 'if (false)',
'#instantiateWasm(fallbackCallback, imports, successCallback) {': '#instantiateWasm(fallbackCallback, imports, successCallback) { return;',
'#getJsModule(fallbackCallback) {': '#getJsModule(fallbackCallback) { return;',
// Mock the `@napi-rs/canvas` module import from the unused `NodeCanvasFactory` class.
'require("@napi-rs/canvas")': canvasMock,
// Remove the legacy build warning.
'warn("Please use the `legacy` build in Node.js environments.")': '',
},
}),
esbuild({ include: /\/src\/.*\.ts$/ }),
nodeResolve(),
pdfjsTypes(),
minify({
keepNames: true,
legalComments: 'none',
target: 'es2022',
}),
],
})