Change how we're passing pdf.sandbox.js-specific options to createWebpackConfig in gulpfile.js

Given the somewhat "specialized" nature of the `pdf.sandbox.js` building, it ought to be possible to re-factor how some of the options are handled.
Note in particular that the `gulp-strip-comments` dependency seems somewhat unncessary, since the *main* source of comments are just the default license header. Hence I seems much more reasonable to simply not include that to begin with, rather than removing it after the fact (the few remaining Webpack-related should be few/small enough to not really matter much in practice).

This way we're able to further reduce the special-casing related to the `pdf.sandbox.js`-building, which will make future changes/maintenance easier by bringing this code more in-line with existing patterns in `gulpfile.js`.

(If we really want to reduce the filesize, we might want to consider always minifying the `GENERIC`-build of the `pdf.sandbox.js` file.)
This commit is contained in:
Jonas Jenwald 2020-12-04 15:49:13 +01:00
parent d742e3cde8
commit 1f29d27474
3 changed files with 29 additions and 118 deletions

View File

@ -33,7 +33,6 @@ var stream = require("stream");
var exec = require("child_process").exec;
var spawn = require("child_process").spawn;
var spawnSync = require("child_process").spawnSync;
var stripComments = require("gulp-strip-comments");
var streamqueue = require("streamqueue");
var merge = require("merge-stream");
var zip = require("gulp-zip");
@ -98,7 +97,6 @@ const DEFINES = Object.freeze({
PRODUCTION: true,
SKIP_BABEL: true,
TESTING: false,
NO_SOURCE_MAP: false,
// The main build targets:
GENERIC: false,
MOZCENTRAL: false,
@ -171,7 +169,11 @@ function createStringSource(filename, content) {
return source;
}
function createWebpackConfig(defines, output) {
function createWebpackConfig(
defines,
output,
{ disableSourceMaps = false, disableLicenseHeader = false } = {}
) {
var versionInfo = getVersionJSON();
var bundleDefines = builder.merge(defines, {
BUNDLE_VERSION: versionInfo.version,
@ -185,7 +187,7 @@ function createWebpackConfig(defines, output) {
!bundleDefines.MOZCENTRAL &&
!bundleDefines.CHROME &&
!bundleDefines.TESTING &&
!bundleDefines.NO_SOURCE_MAP;
!disableSourceMaps;
var skipBabel = bundleDefines.SKIP_BABEL;
// `core-js` (see https://github.com/zloirock/core-js/issues/514),
@ -201,6 +203,13 @@ function createWebpackConfig(defines, output) {
}
const babelExcludeRegExp = new RegExp(`(${babelExcludes.join("|")})`);
const plugins = [];
if (!disableLicenseHeader) {
plugins.push(
new webpack2.BannerPlugin({ banner: licenseHeaderLibre, raw: true })
);
}
// Required to expose e.g., the `window` object.
output.globalObject = "this";
@ -210,9 +219,7 @@ function createWebpackConfig(defines, output) {
performance: {
hints: false, // Disable messages about larger file sizes.
},
plugins: [
new webpack2.BannerPlugin({ banner: licenseHeaderLibre, raw: true }),
],
plugins,
resolve: {
alias: {
pdfjs: path.join(__dirname, "src"),
@ -329,16 +336,20 @@ function createMainBundle(defines) {
.pipe(replaceJSRootName(mainAMDName, "pdfjsLib"));
}
function createScriptingBundle(defines) {
function createScriptingBundle(defines, extraOptions = undefined) {
var scriptingAMDName = "pdfjs-dist/build/pdf.scripting";
var scriptingOutputName = "pdf.scripting.js";
var scriptingFileConfig = createWebpackConfig(defines, {
filename: scriptingOutputName,
library: scriptingAMDName,
libraryTarget: "umd",
umdNamedDefine: true,
});
var scriptingFileConfig = createWebpackConfig(
defines,
{
filename: scriptingOutputName,
library: scriptingAMDName,
libraryTarget: "umd",
umdNamedDefine: true,
},
extraOptions
);
return gulp
.src("./src/pdf.scripting.js")
.pipe(webpack2Stream(scriptingFileConfig))
@ -369,9 +380,10 @@ function createSandboxBundle(defines, code) {
}
function buildSandbox(defines, dir) {
const scriptingDefines = builder.merge(defines, { NO_SOURCE_MAP: true });
return createScriptingBundle(scriptingDefines)
.pipe(stripComments())
return createScriptingBundle(defines, {
disableSourceMaps: true,
disableLicenseHeader: true,
})
.pipe(gulp.dest(dir + "build"))
.on("data", file => {
const content = file.contents.toString();

100
package-lock.json generated
View File

@ -2178,15 +2178,6 @@
"ansi-wrap": "^0.1.0"
}
},
"ansi-cyan": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-cyan/-/ansi-cyan-0.1.1.tgz",
"integrity": "sha1-U4rlKK+JgvKK4w2G8vF0VtJgmHM=",
"dev": true,
"requires": {
"ansi-wrap": "0.1.0"
}
},
"ansi-gray": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-gray/-/ansi-gray-0.1.1.tgz",
@ -2196,15 +2187,6 @@
"ansi-wrap": "0.1.0"
}
},
"ansi-red": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-red/-/ansi-red-0.1.1.tgz",
"integrity": "sha1-jGOPnRCAgAo1PJwoyKgcpHBdlGw=",
"dev": true,
"requires": {
"ansi-wrap": "0.1.0"
}
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
@ -4028,15 +4010,6 @@
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
"dev": true
},
"decomment": {
"version": "0.9.3",
"resolved": "https://registry.npmjs.org/decomment/-/decomment-0.9.3.tgz",
"integrity": "sha512-5skH5BfUL3n09RDmMVaHS1QGCiZRnl2nArUwmsE9JRY93Ueh3tihYl5wIrDdAuXnoFhxVis/DmRWREO2c6DG3w==",
"dev": true,
"requires": {
"esprima": "4.0.1"
}
},
"decompress-response": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz",
@ -7073,79 +7046,6 @@
"replacestream": "^4.0.0"
}
},
"gulp-strip-comments": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/gulp-strip-comments/-/gulp-strip-comments-2.5.2.tgz",
"integrity": "sha512-lb1bW7rsPWDD8f4ZPSguDvmCdjKmjr5HR4yZb9ros3sLl5AfW7oUj8KzY9/VRisT7dG8dL7hVHzNpQEVxfwZGQ==",
"dev": true,
"requires": {
"decomment": "^0.9.0",
"plugin-error": "^0.1.2",
"through2": "^2.0.3"
},
"dependencies": {
"arr-diff": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-1.1.0.tgz",
"integrity": "sha1-aHwydYFjWI/vfeezb6vklesaOZo=",
"dev": true,
"requires": {
"arr-flatten": "^1.0.1",
"array-slice": "^0.2.3"
}
},
"arr-union": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz",
"integrity": "sha1-IPnqtexw9cfSFbEHexw5Fh0pLH0=",
"dev": true
},
"array-slice": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz",
"integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU=",
"dev": true
},
"extend-shallow": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz",
"integrity": "sha1-Gda/lN/AnXa6cR85uHLSH/TdkHE=",
"dev": true,
"requires": {
"kind-of": "^1.1.0"
}
},
"kind-of": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz",
"integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=",
"dev": true
},
"plugin-error": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz",
"integrity": "sha1-O5uzM1zPAPQl4HQ34ZJ2ln2kes4=",
"dev": true,
"requires": {
"ansi-cyan": "^0.1.1",
"ansi-red": "^0.1.1",
"arr-diff": "^1.0.1",
"arr-union": "^2.0.1",
"extend-shallow": "^1.1.2"
}
},
"through2": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz",
"integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==",
"dev": true,
"requires": {
"readable-stream": "~2.3.6",
"xtend": "~4.0.1"
}
}
}
},
"gulp-zip": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/gulp-zip/-/gulp-zip-5.0.2.tgz",

View File

@ -30,7 +30,6 @@
"gulp-postcss": "^9.0.0",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.0.0",
"gulp-strip-comments": "^2.5.2",
"gulp-zip": "^5.0.2",
"jasmine": "^3.6.3",
"jsdoc": "^3.6.6",