Skip to content

Commit

Permalink
Merge pull request mozilla#4025 from gjuggler/singlefile
Browse files Browse the repository at this point in the history
Add singlefile build target
  • Loading branch information
yurydelendik committed Dec 20, 2013
2 parents c0088f5 + 1838ec0 commit cfb4e95
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
65 changes: 57 additions & 8 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ var DEFINES = {
FIREFOX: false,
MOZCENTRAL: false,
B2G: false,
CHROME: false
CHROME: false,
SINGLE_FILE: false
};

//
Expand Down Expand Up @@ -273,31 +274,29 @@ target.bundle = function(args) {
if (!test('-d', BUILD_DIR))
mkdir(BUILD_DIR);

var MAIN_SRC_FILES = [
var SHARED_SRC_FILES = [
'shared/util.js',
'shared/colorspace.js',
'shared/pattern.js',
'shared/function.js',
'shared/annotation.js',
];

var MAIN_SRC_FILES = SHARED_SRC_FILES.concat([
'display/api.js',
'display/metadata.js',
'display/canvas.js',
'display/font_loader.js'
];
]);

var WORKER_SRC_FILES = [
'shared/util.js',
'shared/pattern.js',
'shared/function.js',
'shared/annotation.js',
'core/network.js',
'core/chunked_stream.js',
'core/pdf_manager.js',
'core/core.js',
'core/obj.js',
'core/charsets.js',
'core/cidmaps.js',
'shared/colorspace.js',
'core/crypto.js',
'core/evaluator.js',
'core/fonts.js',
Expand All @@ -314,6 +313,12 @@ target.bundle = function(args) {
'core/cmap.js'
];

if (!defines.SINGLE_FILE) {
// We want shared_src_files in both pdf.js and pdf.worker.js
// unless it's being built in singlefile mode.
WORKER_SRC_FILES = SHARED_SRC_FILES.concat(WORKER_SRC_FILES);
}

var EXT_SRC_FILES = [
'../external/jpgjs/jpg.js'
];
Expand All @@ -328,6 +333,50 @@ target.bundle = function(args) {
rm(srcCopy);
};

//
// make singlefile
// Concatenates pdf.js and pdf.worker.js into one big pdf.combined.js, and
// flags the script loader to not attempt to load the separate worker JS file.
//
target.singlefile = function() {
cd(ROOT_DIR);
echo();
echo('### Creating singlefile build');

var SINGLE_FILE_DIR = BUILD_DIR + '/singlefile/';
var SINGLE_FILE_TARGET = BUILD_DIR + 'pdf.combined.js';

var defines = builder.merge(DEFINES, {SINGLE_FILE: true});
target.bundle({defines: defines});

cd(ROOT_DIR);

rm('-rf', SINGLE_FILE_DIR);
mkdir('-p', SINGLE_FILE_DIR);
mkdir('-p', SINGLE_FILE_DIR + BUILD_DIR);

var setup = {
defines: defines,
copy: [],
preprocess: [
[BUILD_TARGETS, SINGLE_FILE_DIR + BUILD_DIR]
]
};
builder.build(setup);

cd(SINGLE_FILE_DIR);

echo();
echo('### Concatenating pdf.js and pdf.worker.js into pdf.combined.js');
var pdfJs = cat(BUILD_TARGET);
pdfJs += cat(BUILD_WORKER_TARGET);
pdfJs.to(SINGLE_FILE_TARGET);

rm(BUILD_TARGET);
rm(BUILD_WORKER_TARGET);

};

function cleanupJSSource(file) {
var content = cat(file);

Expand Down
8 changes: 7 additions & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
// all requirements to run parts of pdf.js in a web worker.
// Right now, the requirement is, that an Uint8Array is still an Uint8Array
// as it arrives on the worker. Chrome added this with version 15.
//#if !SINGLE_FILE
if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
var workerSrc = PDFJS.workerSrc;
if (!workerSrc) {
Expand Down Expand Up @@ -591,6 +592,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
info('The worker has been disabled.');
}
}
//#endif
// Either workers are disabled, not supported or have thrown an exception.
// Thus, we fallback to a faked worker.
globalScope.PDFJS.disableWorker = true;
Expand Down Expand Up @@ -619,7 +621,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
// pdf.worker.js file is needed.
//#if !PRODUCTION
Util.loadScript(PDFJS.workerSrc);
//#else
//#endif
//#if PRODUCTION && SINGLE_FILE
// PDFJS.fakeWorkerFilesLoadedPromise.resolve();
//#endif
//#if PRODUCTION && !SINGLE_FILE
// Util.loadScript(PDFJS.workerSrc, function() {
// PDFJS.fakeWorkerFilesLoadedPromise.resolve();
// });
Expand Down

0 comments on commit cfb4e95

Please sign in to comment.