From 2075800828ddc4d9498dd01b299097e4c9c17a94 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 2 Sep 2022 18:15:42 +0200 Subject: [PATCH] Remove the `browserify` example This patch proposes removing the `browserify` example for the following reasons: - The last `browserify` release was almost two years ago, according to both https://github.com/browserify/browserify/releases and https://www.npmjs.com/package/browserify?activeTab=versions - The project no longer seems to be actively maintained, since so far this year there's only been *a single* (seemingly trivial) patch merged; see https://github.com/browserify/browserify/commits/master - Because of the previous points `browserify` doesn't support modern and up-to-date JavaScript features, as evident from e.g. issue 14731 and multiple issues found in https://github.com/browserify/browserify/issues - Our `browserify` example is most likely not very commonly used, judging by the very low volume of issues/PRs related to it. Looking at the `git` history of that example the only changes have been lint- or maintenance-related.[1] - Providing an example for a framework that's no longer actively maintained doesn't seem like a good idea in general, since we probably don't want to steer users towards using (possibly) older frameworks. - Given that we've never used `browserify` in the PDF.js project, it's also quite difficult to provide support for the example. --- [1] It's interesting to compare with the `webpack` example, since that's generated both issues *and* also PRs (for missing features) from users. --- examples/browserify/.gitignore | 1 - examples/browserify/README.md | 26 --------------------- examples/browserify/gulpfile.js | 40 -------------------------------- examples/browserify/index.html | 11 --------- examples/browserify/main.js | 35 ---------------------------- examples/browserify/package.json | 16 ------------- examples/browserify/worker.js | 9 ------- 7 files changed, 138 deletions(-) delete mode 100644 examples/browserify/.gitignore delete mode 100644 examples/browserify/README.md delete mode 100644 examples/browserify/gulpfile.js delete mode 100644 examples/browserify/index.html delete mode 100644 examples/browserify/main.js delete mode 100644 examples/browserify/package.json delete mode 100644 examples/browserify/worker.js diff --git a/examples/browserify/.gitignore b/examples/browserify/.gitignore deleted file mode 100644 index c2658d7d1..000000000 --- a/examples/browserify/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/examples/browserify/README.md b/examples/browserify/README.md deleted file mode 100644 index 22ddbdf38..000000000 --- a/examples/browserify/README.md +++ /dev/null @@ -1,26 +0,0 @@ -## Overview - -Example to demonstrate PDF.js library usage with Browserify. - -## Getting started - -Build project and install the example dependencies: - - $ gulp dist-install - $ cd examples/browserify - $ npm install - -To build Browserify bundles, run `gulp build`. If you are running -a web server, you can observe the build results at -http://localhost:8888/examples/browserify/index.html - -See main.js, worker.js and gulpfile.js files. Please notice that PDF.js -packaging requires packaging of the main application and PDF.js worker code, -and the `workerSrc` path shall be set to the latter file. The pdf.worker.js file -shall be excluded from the main bundle. - -Alternatives to the gulp commands (without compression) are: - - $ mkdir -p ../../build/browserify - $ node_modules/.bin/browserify main.js -u ./node_modules/pdfjs-dist/build/pdf.worker.js -o ../../build/browserify/main.bundle.js - $ node_modules/.bin/browserify worker.js -o ../../build/browserify/pdf.worker.bundle.js diff --git a/examples/browserify/gulpfile.js b/examples/browserify/gulpfile.js deleted file mode 100644 index 15661bbfd..000000000 --- a/examples/browserify/gulpfile.js +++ /dev/null @@ -1,40 +0,0 @@ -const gulp = require("gulp"); -const browserify = require("browserify"); -const streamify = require("gulp-streamify"); -const rename = require("gulp-rename"); -const uglify = require("gulp-uglify"); -const source = require("vinyl-source-stream"); - -const OUTPUT_PATH = "../../build/browserify"; -const TMP_FILE_PREFIX = "../../build/browserify_"; - -gulp.task("build-bundle", function () { - return browserify("main.js", { output: TMP_FILE_PREFIX + "main.tmp" }) - .ignore(require.resolve("pdfjs-dist/build/pdf.worker")) // Reducing size - .bundle() - .pipe(source(TMP_FILE_PREFIX + "main.tmp")) - .pipe(streamify(uglify())) - .pipe(rename("main.bundle.js")) - .pipe(gulp.dest(OUTPUT_PATH)); -}); - -gulp.task("build-worker", function () { - // We can create our own viewer (see worker.js) or use already defined one. - const workerSrc = require.resolve("pdfjs-dist/build/pdf.worker.entry"); - return browserify(workerSrc, { output: TMP_FILE_PREFIX + "worker.tmp" }) - .bundle() - .pipe(source(TMP_FILE_PREFIX + "worker.tmp")) - .pipe( - streamify( - uglify({ - compress: { - sequences: false, // Chrome has issue with the generated code if true - }, - }) - ) - ) - .pipe(rename("pdf.worker.bundle.js")) - .pipe(gulp.dest(OUTPUT_PATH)); -}); - -gulp.task("build", gulp.series("build-bundle", "build-worker")); diff --git a/examples/browserify/index.html b/examples/browserify/index.html deleted file mode 100644 index 8bd4644d6..000000000 --- a/examples/browserify/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - browserify example - - - - - - diff --git a/examples/browserify/main.js b/examples/browserify/main.js deleted file mode 100644 index f033660ef..000000000 --- a/examples/browserify/main.js +++ /dev/null @@ -1,35 +0,0 @@ -// Any copyright is dedicated to the Public Domain. -// http://creativecommons.org/licenses/publicdomain/ - -// Hello world example for browserify. - -const pdfjsLib = require("pdfjs-dist"); - -const pdfPath = "../learning/helloworld.pdf"; - -// Setting worker path to worker bundle. -pdfjsLib.GlobalWorkerOptions.workerSrc = - "../../build/browserify/pdf.worker.bundle.js"; - -// Loading a document. -const loadingTask = pdfjsLib.getDocument(pdfPath); -loadingTask.promise - .then(function (pdfDocument) { - // Request a first page - return pdfDocument.getPage(1).then(function (pdfPage) { - // Display page on the existing canvas with 100% scale. - const viewport = pdfPage.getViewport({ scale: 1.0 }); - const canvas = document.getElementById("theCanvas"); - canvas.width = viewport.width; - canvas.height = viewport.height; - const ctx = canvas.getContext("2d"); - const renderTask = pdfPage.render({ - canvasContext: ctx, - viewport, - }); - return renderTask.promise; - }); - }) - .catch(function (reason) { - console.error("Error: " + reason); - }); diff --git a/examples/browserify/package.json b/examples/browserify/package.json deleted file mode 100644 index 60ee4405c..000000000 --- a/examples/browserify/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "browserify-pdf.js-example", - "version": "0.1.0", - "devDependencies": { - "browserify": "^13.0.0", - "gulp": "^3.9.1", - "gulp-rename": "^1.2.2", - "gulp-streamify": "^1.0.2", - "gulp-uglify": "^1.5.3", - "pdfjs-dist": "../../node_modules/pdfjs-dist", - "vinyl-source-stream": "^1.1.0" - }, - "scripts": { - "build": "gulp build" - } -} diff --git a/examples/browserify/worker.js b/examples/browserify/worker.js deleted file mode 100644 index 3ae28b39f..000000000 --- a/examples/browserify/worker.js +++ /dev/null @@ -1,9 +0,0 @@ -// Any copyright is dedicated to the Public Domain. -// http://creativecommons.org/licenses/publicdomain/ - -// Hello world example for browserify: worker bundle. - -(typeof window !== "undefined" - ? window - : {} -).pdfjsWorker = require("pdfjs-dist/build/pdf.worker");