2016-04-05 01:32:01 +09:00
|
|
|
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() {
|
2018-12-06 21:55:15 +09:00
|
|
|
return browserify('main.js', { output: TMP_FILE_PREFIX + 'main.tmp', })
|
2016-04-13 22:24:25 +09:00
|
|
|
.ignore(require.resolve('pdfjs-dist/build/pdf.worker')) // Reducing size
|
2016-04-05 01:32:01 +09:00
|
|
|
.bundle()
|
|
|
|
.pipe(source(TMP_FILE_PREFIX + 'main.tmp'))
|
|
|
|
.pipe(streamify(uglify()))
|
2016-04-13 22:24:25 +09:00
|
|
|
.pipe(rename('main.bundle.js'))
|
2016-04-05 01:32:01 +09:00
|
|
|
.pipe(gulp.dest(OUTPUT_PATH));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build-worker', function() {
|
2016-04-13 22:24:25 +09:00
|
|
|
// We can create our own viewer (see worker.js) or use already defined one.
|
|
|
|
var workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.entry');
|
2018-12-06 21:55:15 +09:00
|
|
|
return browserify(workerSrc, { output: TMP_FILE_PREFIX + 'worker.tmp', })
|
2016-04-05 01:32:01 +09:00
|
|
|
.bundle()
|
|
|
|
.pipe(source(TMP_FILE_PREFIX + 'worker.tmp'))
|
2018-12-06 22:02:39 +09:00
|
|
|
.pipe(streamify(uglify({
|
|
|
|
compress: {
|
|
|
|
sequences: false, // Chrome has issue with the generated code if true
|
|
|
|
},
|
|
|
|
})))
|
2016-04-05 01:32:01 +09:00
|
|
|
.pipe(rename('pdf.worker.bundle.js'))
|
|
|
|
.pipe(gulp.dest(OUTPUT_PATH));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build', ['build-bundle', 'build-worker']);
|