Fix pdf.js bundling

This commit is contained in:
Bill Thornton 2024-09-12 13:35:07 -04:00
parent 4f6586f4ee
commit 0bff49344f
5 changed files with 82 additions and 9 deletions

View File

@ -3,7 +3,8 @@
"modules": "false",
"files": "./dist/**/*.js",
"not": [
"./dist/libraries/pdf.worker.js",
"./dist/libraries/pdf.worker.mjs",
"./dist/node_modules.pdfjs-dist.*",
"./dist/libraries/worker-bundle.js",
"./dist/serviceworker.js"
]

71
package-lock.json generated
View File

@ -119,6 +119,7 @@
"stylelint-no-browser-hacks": "1.3.0",
"stylelint-order": "6.0.4",
"stylelint-scss": "5.3.2",
"transform-async-modules-webpack-plugin": "1.1.1",
"ts-loader": "9.5.1",
"typescript": "5.5.4",
"vitest": "2.0.5",
@ -1677,6 +1678,26 @@
"@babel/core": "^7.0.0-0"
}
},
"node_modules/@babel/plugin-transform-runtime": {
"version": "7.25.4",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.25.4.tgz",
"integrity": "sha512-8hsyG+KUYGY0coX6KUCDancA0Vw225KJ2HJO0yCNr1vq5r+lJTleDaJf0K7iOhjw4SWhu03TMBzYTJ9krmzULQ==",
"dev": true,
"dependencies": {
"@babel/helper-module-imports": "^7.24.7",
"@babel/helper-plugin-utils": "^7.24.8",
"babel-plugin-polyfill-corejs2": "^0.4.10",
"babel-plugin-polyfill-corejs3": "^0.10.6",
"babel-plugin-polyfill-regenerator": "^0.6.1",
"semver": "^6.3.1"
},
"engines": {
"node": ">=6.9.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
}
},
"node_modules/@babel/plugin-transform-shorthand-properties": {
"version": "7.24.7",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.7.tgz",
@ -24692,6 +24713,31 @@
"node": ">=18"
}
},
"node_modules/transform-async-modules-webpack-plugin": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/transform-async-modules-webpack-plugin/-/transform-async-modules-webpack-plugin-1.1.1.tgz",
"integrity": "sha512-hBr1zAid46Aa1y/iSHMl8uufw5NGgPtPhWlKrzUoc53fVguCzMu64eXFdKtnu86ZfhblOPl5oHafWlt+60uDCg==",
"dev": true,
"dependencies": {
"@babel/core": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.0",
"@babel/preset-env": "^7.13.0"
},
"engines": {
"node": ">=16"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/steverep"
},
"peerDependencies": {
"@babel/core": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.0",
"@babel/preset-env": "^7.13.0",
"@babel/runtime": "^7.13.0",
"webpack": "^5.0.0"
}
},
"node_modules/tree-dump": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/tree-dump/-/tree-dump-1.0.1.tgz",
@ -27940,6 +27986,20 @@
"@babel/helper-plugin-utils": "^7.24.7"
}
},
"@babel/plugin-transform-runtime": {
"version": "7.25.4",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.25.4.tgz",
"integrity": "sha512-8hsyG+KUYGY0coX6KUCDancA0Vw225KJ2HJO0yCNr1vq5r+lJTleDaJf0K7iOhjw4SWhu03TMBzYTJ9krmzULQ==",
"dev": true,
"requires": {
"@babel/helper-module-imports": "^7.24.7",
"@babel/helper-plugin-utils": "^7.24.8",
"babel-plugin-polyfill-corejs2": "^0.4.10",
"babel-plugin-polyfill-corejs3": "^0.10.6",
"babel-plugin-polyfill-regenerator": "^0.6.1",
"semver": "^6.3.1"
}
},
"@babel/plugin-transform-shorthand-properties": {
"version": "7.24.7",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.7.tgz",
@ -43196,6 +43256,17 @@
"punycode": "^2.3.1"
}
},
"transform-async-modules-webpack-plugin": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/transform-async-modules-webpack-plugin/-/transform-async-modules-webpack-plugin-1.1.1.tgz",
"integrity": "sha512-hBr1zAid46Aa1y/iSHMl8uufw5NGgPtPhWlKrzUoc53fVguCzMu64eXFdKtnu86ZfhblOPl5oHafWlt+60uDCg==",
"dev": true,
"requires": {
"@babel/core": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.0",
"@babel/preset-env": "^7.13.0"
}
},
"tree-dump": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/tree-dump/-/tree-dump-1.0.1.tgz",

View File

@ -59,6 +59,7 @@
"stylelint-no-browser-hacks": "1.3.0",
"stylelint-order": "6.0.4",
"stylelint-scss": "5.3.2",
"transform-async-modules-webpack-plugin": "1.1.1",
"ts-loader": "9.5.1",
"typescript": "5.5.4",
"vitest": "2.0.5",

View File

@ -205,13 +205,10 @@ export class PdfPlayer {
const downloadHref = apiClient.getItemDownloadUrl(item.Id);
this.bindEvents();
GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.js';
GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.min.mjs';
const downloadTask = getDocument({
url: downloadHref,
// Disable for PDF.js XSS vulnerability
// https://github.com/mozilla/pdf.js/security/advisories/GHSA-wgrm-67xf-hhpq
isEvalSupported: false
url: downloadHref
});
return downloadTask.promise.then(book => {
if (this.cancellationToken) return;

View File

@ -4,6 +4,7 @@ const CopyPlugin = require('copy-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { TransformAsyncModulesPlugin } = require('transform-async-modules-webpack-plugin');
const { DefinePlugin, IgnorePlugin } = require('webpack');
const packageJson = require('./package.json');
@ -15,7 +16,7 @@ const Assets = [
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.js',
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.wasm',
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker-legacy.js',
'pdfjs-dist/build/pdf.worker.js'
'pdfjs-dist/build/pdf.worker.min.mjs'
];
const DEV_MODE = process.env.NODE_ENV !== 'production';
@ -109,7 +110,9 @@ const config = {
typescript: {
configFile: path.resolve(__dirname, 'tsconfig.json')
}
})
}),
// Transform any modules using top-level await (pdf.js)
new TransformAsyncModulesPlugin()
],
output: {
filename: pathData => (
@ -205,6 +208,7 @@ const config = {
path.resolve(__dirname, 'node_modules/markdown-it'),
path.resolve(__dirname, 'node_modules/material-react-table'),
path.resolve(__dirname, 'node_modules/mdurl'),
path.resolve(__dirname, 'node_modules/pdfjs-dist'),
path.resolve(__dirname, 'node_modules/punycode'),
path.resolve(__dirname, 'node_modules/react-blurhash'),
path.resolve(__dirname, 'node_modules/react-lazy-load-image-component'),
@ -268,7 +272,6 @@ const config = {
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'node_modules/pdfjs-dist'),
path.resolve(__dirname, 'node_modules/xmldom')
],
use: [{