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.
This commit is contained in:
parent
c503006b2e
commit
2075800828
1
examples/browserify/.gitignore
vendored
1
examples/browserify/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
node_modules/
|
|
@ -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
|
|
@ -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"));
|
|
@ -1,11 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>browserify example</title>
|
|
||||||
<script src="../../build/browserify/main.bundle.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<canvas id="theCanvas"></canvas>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -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);
|
|
||||||
});
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
@ -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");
|
|
Loading…
x
Reference in New Issue
Block a user