Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the gulp minified command to use uglify-es #8831

Merged
merged 1 commit into from
Aug 27, 2017
Merged

Update the gulp minified command to use uglify-es #8831

merged 1 commit into from
Aug 27, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

By updating to uglify-es, rather than uglify-js, the minifier itself now supports ES6 code. This means that it's now possible to minify code built with PDFJS_NEXT = true set, i.e. with Babel transpilation disabled, which wasn't the case previously.

Note that uglify-es is based on the API of uglify-js v3, which differs from the one that we previously used.
Of particular importance is the fact that it's no longer possible to provide a path to a file for minification, but one must instead directly provide the source of the file.

For more information, please see https://github.com/mishoo/UglifyJS2/tree/harmony

gulpfile.js Outdated

console.log();
console.log('### Minifying js files');

var UglifyJS = require('uglify-js');
var UglifyJS = require('uglify-es');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be UglifyES. If you want to avoid that, you can also choose uglifier as a more generic name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

];
var pdfFile = fs.readFileSync(MINIFIED_DIR + '/build/pdf.js').toString();
var pdfWorkerFile =
fs.readFileSync(MINIFIED_DIR + '/build/pdf.worker.js').toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use BUILD_DIR here and in the other parts of this patch to not hardcode that and to be consistent with other places in the Gulpfile.

Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just moving existing code around, but I suppose it wouldn't hurt to change this :-)

Edit: Actually, looking through the rest of gulpfile.js, it seems to (almost) exclusively be used when defining other constants, so I'm now not so sure if we really ought to be using it "the other way around" here!?

pdf.js/gulpfile.js

Lines 46 to 58 in 7cc7260

var BASELINE_DIR = BUILD_DIR + 'baseline/';
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/';
var GENERIC_DIR = BUILD_DIR + 'generic/';
var COMPONENTS_DIR = BUILD_DIR + 'components/';
var SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/';
var MINIFIED_DIR = BUILD_DIR + 'minified/';
var FIREFOX_BUILD_DIR = BUILD_DIR + 'firefox/';
var CHROME_BUILD_DIR = BUILD_DIR + 'chromium/';
var JSDOC_BUILD_DIR = BUILD_DIR + 'jsdoc/';
var GH_PAGES_DIR = BUILD_DIR + 'gh-pages/';
var SRC_DIR = 'src/';
var LIB_DIR = BUILD_DIR + 'lib/';
var DIST_DIR = BUILD_DIR + 'dist/';

By updating to uglify-es, rather than uglify-js, the minifier *itself* now supports ES6 code. This means that it's now possible to minify code built with `PDFJS_NEXT = true` set, i.e. with Babel transpilation disabled, which wasn't the case previously.

Note that uglify-es is based on the API of uglify-js v3, which differs from the one that we previously used.
Of particular importance is the fact that it's no longer possible to provide a path to a file for minification, but one must instead directly provide the source of the file.

For more information, please see https://github.com/mishoo/UglifyJS2/tree/harmony
@timvandermeij timvandermeij merged commit f54dfc6 into mozilla:master Aug 27, 2017
@timvandermeij
Copy link
Contributor

Works fine, thank you!

@Snuffleupagus Snuffleupagus deleted the uglify-es branch August 27, 2017 17:31
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Update the `gulp minified` command to use uglify-es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants