Skip to content

Commit

Permalink
Split the createBundle helper function, in gulpfile.js, into separa…
Browse files Browse the repository at this point in the history
…te ones for the main/worker-thread files

All of the other *similar* helper functions only target one file per function, and there's no particular reason for this one to be different.
This patch will simplify future changes, e.g. experimenting with using `gulp watch` instead of SystemJS for the development viewer.
  • Loading branch information
Snuffleupagus committed May 3, 2020
1 parent 21495c1 commit a9e7798
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ function replaceJSRootName(amdName, jsName) {
);
}

function createBundle(defines) {
console.log();
console.log("### Bundling files into pdf.js");

function createMainBundle(defines) {
var mainAMDName = "pdfjs-dist/build/pdf";
var mainOutputName = "pdf.js";

Expand All @@ -309,12 +306,14 @@ function createBundle(defines) {
libraryTarget: "umd",
umdNamedDefine: true,
});
var mainOutput = gulp
return gulp
.src("./src/pdf.js")
.pipe(webpack2Stream(mainFileConfig))
.pipe(replaceWebpackRequire())
.pipe(replaceJSRootName(mainAMDName, "pdfjsLib"));
}

function createWorkerBundle(defines) {
var workerAMDName = "pdfjs-dist/build/pdf.worker";
var workerOutputName = "pdf.worker.js";

Expand All @@ -324,13 +323,11 @@ function createBundle(defines) {
libraryTarget: "umd",
umdNamedDefine: true,
});

var workerOutput = gulp
return gulp
.src("./src/pdf.worker.js")
.pipe(webpack2Stream(workerFileConfig))
.pipe(replaceWebpackRequire())
.pipe(replaceJSRootName(workerAMDName, "pdfjsWorker"));
return merge([mainOutput, workerOutput]);
}

function createWebBundle(defines) {
Expand Down Expand Up @@ -706,7 +703,8 @@ function buildGeneric(defines, dir) {
rimraf.sync(dir);

return merge([
createBundle(defines).pipe(gulp.dest(dir + "build")),
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
createWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
createWebBundle(defines).pipe(gulp.dest(dir + "web")),
gulp.src(COMMON_WEB_FILES, { base: "web/" }).pipe(gulp.dest(dir + "web")),
gulp.src("LICENSE").pipe(gulp.dest(dir)),
Expand Down Expand Up @@ -840,7 +838,8 @@ gulp.task(
rimraf.sync(MINIFIED_DIR);

return merge([
createBundle(defines).pipe(gulp.dest(MINIFIED_DIR + "build")),
createMainBundle(defines).pipe(gulp.dest(MINIFIED_DIR + "build")),
createWorkerBundle(defines).pipe(gulp.dest(MINIFIED_DIR + "build")),
createWebBundle(defines).pipe(gulp.dest(MINIFIED_DIR + "web")),
createImageDecodersBundle(
builder.merge(defines, { IMAGE_DECODERS: true })
Expand Down Expand Up @@ -1000,7 +999,12 @@ gulp.task(
];

return merge([
createBundle(defines).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")),
createMainBundle(defines).pipe(
gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")
),
createWorkerBundle(defines).pipe(
gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")
),
createWebBundle(defines).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
gulp
.src(MOZCENTRAL_COMMON_WEB_FILES, { base: "web/" })
Expand Down Expand Up @@ -1055,7 +1059,12 @@ gulp.task(
var version = getVersionJSON().version;

return merge([
createBundle(defines).pipe(gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")),
createMainBundle(defines).pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
),
createWorkerBundle(defines).pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
),
createWebBundle(defines).pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "web")
),
Expand Down

0 comments on commit a9e7798

Please sign in to comment.