From 1c2d200918563a6b5260822a82b3d2adf9811fbe Mon Sep 17 00:00:00 2001 From: Sam Magura Date: Mon, 12 Sep 2022 21:40:58 -0400 Subject: [PATCH] [api-minor] Use new Worker() syntax in webpack entrypoint This requires Webpack 5 and will break for anyone using Webpack 4. worker-loader no longer needs to be installed. --- examples/webpack/README.md | 5 +---- external/dist/webpack.js | 5 +++-- gulpfile.js | 8 -------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/examples/webpack/README.md b/examples/webpack/README.md index 0ea1aaed9..04a078f30 100644 --- a/examples/webpack/README.md +++ b/examples/webpack/README.md @@ -28,10 +28,7 @@ otherwise the build is not guaranteed to work correctly. If you are getting the `Setting up fake worker` warning, make sure you are importing `pdfjs-dist/webpack` which is the zero-configuration method for -Webpack users. You will need to install -[worker-loader](https://github.com/webpack-contrib/worker-loader) (version 3.0.0 or higher is required), as a -dependency in your project in order to use `pdfjs-dist/webpack` (configuring -`worker-loader` is not necessary; just installing it is sufficient). +Webpack users. Installing `worker-loader` is no longer necessary. import * as pdfjsLib from 'pdfjs-dist/webpack'; diff --git a/external/dist/webpack.js b/external/dist/webpack.js index 64481a32b..03704cdd4 100644 --- a/external/dist/webpack.js +++ b/external/dist/webpack.js @@ -16,10 +16,11 @@ "use strict"; const pdfjs = require("./build/pdf.js"); -const PdfjsWorker = require("worker-loader?esModule=false&filename=[name].[contenthash].js!./build/pdf.worker.js"); if (typeof window !== "undefined" && "Worker" in window) { - pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker(); + pdfjs.GlobalWorkerOptions.workerPort = new Worker( + new URL("./build/pdf.worker.js", import.meta.url) + ); } module.exports = pdfjs; diff --git a/gulpfile.js b/gulpfile.js index efaf86226..36e1c767c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2171,14 +2171,6 @@ function packageJson() { dommatrix: "^1.0.3", "web-streams-polyfill": "^3.2.1", }, - peerDependencies: { - "worker-loader": "^3.0.8", // Used in `external/dist/webpack.js`. - }, - peerDependenciesMeta: { - "worker-loader": { - optional: true, - }, - }, browser: { canvas: false, fs: false,