Files
pdf.js/examples/browserify/gulpfile.js
T

41 lines
1.3 KiB
JavaScript
Raw Normal View History

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");
2016-04-04 11:32:01 -05:00
const OUTPUT_PATH = "../../build/browserify";
const TMP_FILE_PREFIX = "../../build/browserify_";
2016-04-04 11:32:01 -05:00
2020-04-14 12:28:14 +02:00
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
2016-04-04 11:32:01 -05:00
.bundle()
.pipe(source(TMP_FILE_PREFIX + "main.tmp"))
2016-04-04 11:32:01 -05:00
.pipe(streamify(uglify()))
.pipe(rename("main.bundle.js"))
2016-04-04 11:32:01 -05:00
.pipe(gulp.dest(OUTPUT_PATH));
});
2020-04-14 12:28:14 +02:00
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" })
2016-04-04 11:32:01 -05:00
.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"))
2016-04-04 11:32:01 -05:00
.pipe(gulp.dest(OUTPUT_PATH));
});
gulp.task("build", gulp.series("build-bundle", "build-worker"));