From 0759066be0f58f56a5115c60ecfa8963d2126d47 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Wed, 8 Feb 2017 16:48:37 -0600 Subject: [PATCH] Saving old-style JS module name of dist libraries. --- gulpfile.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ab86dacd4..2211a8cd9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -167,6 +167,15 @@ function replaceWebpackRequire() { return replace('__webpack_require__', '__w_pdfjs_require__'); } +function replaceJSRootName(amdName) { + // Saving old-style JS module name. + var jsName = amdName.replace(/[\-_\.\/]\w/g, function (all) { + return all[1].toUpperCase(); + }); + return replace('root["' + amdName + '"] = factory()', + 'root["' + amdName + '"] = root.' + jsName + ' = factory()'); +} + function createBundle(defines) { console.log(); console.log('### Bundling files into pdf.js'); @@ -186,7 +195,8 @@ function createBundle(defines) { }); var mainOutput = gulp.src('./src/pdf.js') .pipe(webpack2Stream(mainFileConfig)) - .pipe(replaceWebpackRequire()); + .pipe(replaceWebpackRequire()) + .pipe(replaceJSRootName(mainAMDName)); if (defines.SINGLE_FILE) { return mainOutput; // don't need a worker file. } @@ -202,7 +212,8 @@ function createBundle(defines) { }); var workerOutput = gulp.src('./src/pdf.worker.js') .pipe(webpack2Stream(workerFileConfig)) - .pipe(replaceWebpackRequire()); + .pipe(replaceWebpackRequire()) + .pipe(replaceJSRootName(workerAMDName)); return merge([mainOutput, workerOutput]); } @@ -228,7 +239,8 @@ function createComponentsBundle(defines) { }); return gulp.src('./web/pdf_viewer.component.js') .pipe(webpack2Stream(componentsFileConfig)) - .pipe(replaceWebpackRequire()); + .pipe(replaceWebpackRequire()) + .pipe(replaceJSRootName(componentsAMDName)); } function checkFile(path) {