Browse Source

Produces source maps for built files.

Yury Delendik 8 years ago
parent
commit
996805f953
  1. 15
      external/builder/preprocessor2.js
  2. 19
      external/webpack/pdfjsdev-loader.js
  3. 6
      gulpfile.js

15
external/builder/preprocessor2.js vendored

@ -347,28 +347,23 @@ function traverseTree(ctx, node) {
} }
function preprocessPDFJSCode(ctx, code) { function preprocessPDFJSCode(ctx, code) {
var saveComments = !!ctx.saveComments;
var format = ctx.format || { var format = ctx.format || {
indent: { indent: {
style: ' ', style: ' ',
adjustMultilineComment: saveComments,
} }
}; };
var comments; var parseOptions = {
var parseComment = {
locations: true, locations: true,
onComments: saveComments || (comments = []), sourceFile: ctx.sourceFile,
sourceType: 'module', sourceType: 'module',
}; };
var codegenOptions = { var codegenOptions = {
format: format, format: format,
comment: saveComments,
parse: acorn.parse, parse: acorn.parse,
sourceMap: ctx.sourceMap,
sourceMapWithCode: ctx.sourceMap,
}; };
var syntax = acorn.parse(code, parseComment); var syntax = acorn.parse(code, parseOptions);
if (saveComments) {
escodegen.attachComments(syntax, comments);
}
traverseTree(ctx, syntax); traverseTree(ctx, syntax);
return escodegen.generate(syntax, codegenOptions); return escodegen.generate(syntax, codegenOptions);
} }

19
external/webpack/pdfjsdev-loader.js vendored

@ -17,6 +17,7 @@
'use strict'; 'use strict';
var preprocessor2 = require('../builder/preprocessor2.js'); var preprocessor2 = require('../builder/preprocessor2.js');
var path = require('path');
module.exports = function (source) { module.exports = function (source) {
// Options must be specified, ignoring request if not. // Options must be specified, ignoring request if not.
@ -24,7 +25,19 @@ module.exports = function (source) {
return source; return source;
} }
this.cacheable(); this.cacheable();
var ctx = this.query;
source = preprocessor2.preprocessPDFJSCode(ctx, source); var filePath = this.resourcePath;
return source; var context = this.options.context;
var sourcePath = path.relative(context, filePath).split(path.sep).join('/');
var ctx = Object.create(this.query);
ctx.sourceMap = true;
ctx.sourceFile = sourcePath;
var callback = this.callback;
var sourceAndMap = preprocessor2.preprocessPDFJSCode(ctx, source);
var map = sourceAndMap.map.toJSON();
// escodegen does not embed source -- setting map's sourcesContent.
map.sourcesContent = [source];
callback(null, sourceAndMap.code, map);
}; };

6
gulpfile.js

@ -129,6 +129,8 @@ function createWebpackConfig(defines, output) {
BUNDLE_BUILD: versionInfo.commit BUNDLE_BUILD: versionInfo.commit
}); });
var licenseHeader = fs.readFileSync('./src/license_header.js').toString(); var licenseHeader = fs.readFileSync('./src/license_header.js').toString();
var enableSourceMaps = !bundleDefines.FIREFOX && !bundleDefines.MOZCENTRAL &&
!bundleDefines.CHROME;
return { return {
output: output, output: output,
@ -142,6 +144,7 @@ function createWebpackConfig(defines, output) {
'pdfjs-web': path.join(__dirname, 'web'), 'pdfjs-web': path.join(__dirname, 'web'),
} }
}, },
devtool: enableSourceMaps ? 'source-map' : undefined,
module: { module: {
loaders: [ loaders: [
{ {
@ -1329,8 +1332,11 @@ gulp.task('dist-repo-prepare', ['dist-pre'], function () {
.pipe(gulp.dest(DIST_DIR)), .pipe(gulp.dest(DIST_DIR)),
gulp.src([ gulp.src([
GENERIC_DIR + 'build/pdf.js', GENERIC_DIR + 'build/pdf.js',
GENERIC_DIR + 'build/pdf.js.map',
GENERIC_DIR + 'build/pdf.worker.js', GENERIC_DIR + 'build/pdf.worker.js',
GENERIC_DIR + 'build/pdf.worker.js.map',
SINGLE_FILE_DIR + 'build/pdf.combined.js', SINGLE_FILE_DIR + 'build/pdf.combined.js',
SINGLE_FILE_DIR + 'build/pdf.combined.js.map',
SRC_DIR + 'pdf.worker.entry.js', SRC_DIR + 'pdf.worker.entry.js',
]).pipe(gulp.dest(DIST_DIR + 'build/')), ]).pipe(gulp.dest(DIST_DIR + 'build/')),
gulp.src(MINIFIED_DIR + 'build/pdf.js') gulp.src(MINIFIED_DIR + 'build/pdf.js')

Loading…
Cancel
Save