Actually utilize the PDF.js build-system fully when bundling the pdf.sandbox.js
file
There's no good reason, as far as I can tell, to use search-and-replace to include the *stringified* `pdf.scripting.js` file in the built `pdf.sandbox.js` file. Instead we could, and even should, utilize the existing `PDFJSDev.eval(...)`-functionality, which is not only simpler but will also be more efficient as well (no need for a regular expression).
This commit is contained in:
parent
715b8aa389
commit
d742e3cde8
36
gulpfile.js
36
gulpfile.js
@ -98,6 +98,7 @@ const DEFINES = Object.freeze({
|
||||
PRODUCTION: true,
|
||||
SKIP_BABEL: true,
|
||||
TESTING: false,
|
||||
NO_SOURCE_MAP: false,
|
||||
// The main build targets:
|
||||
GENERIC: false,
|
||||
MOZCENTRAL: false,
|
||||
@ -106,7 +107,6 @@ const DEFINES = Object.freeze({
|
||||
COMPONENTS: false,
|
||||
LIB: false,
|
||||
IMAGE_DECODERS: false,
|
||||
NO_SOURCE_MAP: false,
|
||||
});
|
||||
|
||||
function transform(charEncoding, transformFunction) {
|
||||
@ -350,36 +350,22 @@ function createSandboxBundle(defines, code) {
|
||||
var sandboxAMDName = "pdfjs-dist/build/pdf.sandbox";
|
||||
var sandboxOutputName = "pdf.sandbox.js";
|
||||
|
||||
var sandboxFileConfig = createWebpackConfig(defines, {
|
||||
// Insert the code as a string to be `eval`-ed in the sandbox.
|
||||
const sandboxDefines = builder.merge(defines, {
|
||||
PDF_SCRIPTING_JS_SOURCE: code,
|
||||
});
|
||||
var sandboxFileConfig = createWebpackConfig(sandboxDefines, {
|
||||
filename: sandboxOutputName,
|
||||
library: sandboxAMDName,
|
||||
libraryTarget: "umd",
|
||||
umdNamedDefine: true,
|
||||
});
|
||||
|
||||
// The code is the one from the bundle pdf.scripting.js
|
||||
// so in order to have it in a string (which will be eval-ed
|
||||
// in the sandbox) we must escape some chars.
|
||||
// This way we've all the code (initialization+sandbox) in
|
||||
// the same bundle.
|
||||
code = code.replace(/["\\\n\t]/g, match => {
|
||||
if (match === "\n") {
|
||||
return "\\n";
|
||||
}
|
||||
if (match === "\t") {
|
||||
return "\\t";
|
||||
}
|
||||
return `\\${match}`;
|
||||
});
|
||||
return (
|
||||
gulp
|
||||
.src("./src/pdf.sandbox.js")
|
||||
.pipe(webpack2Stream(sandboxFileConfig))
|
||||
.pipe(replaceWebpackRequire())
|
||||
.pipe(replaceJSRootName(sandboxAMDName, "pdfjsSandbox"))
|
||||
// put the code in a string to be eval-ed in the sandbox
|
||||
.pipe(replace("/* INITIALIZATION_CODE */", `${code}`))
|
||||
);
|
||||
return gulp
|
||||
.src("./src/pdf.sandbox.js")
|
||||
.pipe(webpack2Stream(sandboxFileConfig))
|
||||
.pipe(replaceWebpackRequire())
|
||||
.pipe(replaceJSRootName(sandboxAMDName, "pdfjsSandbox"));
|
||||
}
|
||||
|
||||
function buildSandbox(defines, dir) {
|
||||
|
@ -48,7 +48,7 @@ class Sandbox {
|
||||
"module = Object.create(null);",
|
||||
// Next line is replaced by code from initialization.js
|
||||
// when we create the bundle for the sandbox.
|
||||
"/* INITIALIZATION_CODE */",
|
||||
PDFJSDev.eval("PDF_SCRIPTING_JS_SOURCE"),
|
||||
`data = ${sandboxData};`,
|
||||
`module.exports.initSandbox({ data, extra: {${extraStr}}, out: this});`,
|
||||
"delete exports;",
|
||||
|
Loading…
Reference in New Issue
Block a user