All files / pdf.js/examples/browserify gulpfile.js

0% Statements 0/14
100% Branches 0/0
0% Functions 0/2
0% Lines 0/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                     
var gulp = require('gulp');
var browserify = require('browserify');
var streamify = require('gulp-streamify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
 
var OUTPUT_PATH = '../../build/browserify';
var 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.
  var 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', ['build-bundle', 'build-worker']);