Skip to content

Commit

Permalink
turn off 'typeof' compress options for all minify steps
Browse files Browse the repository at this point in the history
- for consistency and maintainability,
  this does lead to a few extra bytes though.
  • Loading branch information
etpinard committed Jul 9, 2018
1 parent 7171bc4 commit 2a3afe7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
21 changes: 2 additions & 19 deletions tasks/util/browserify_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var browserify = require('browserify');
var minify = require('minify-stream');

var constants = require('./constants');
var compressAttributes = require('./compress_attributes');
var strictD3 = require('./strict_d3');

Expand Down Expand Up @@ -58,26 +59,8 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
});

if(pathToMinBundle) {
var uglifyOptions = {
ecma: 5,
mangle: true,
compress: true,
output: {
beautify: false,
ascii_only: true
},
sourceMap: false
};

// need this to make mapbox-gl work in minified bundles
// see https://github.com/plotly/plotly.js/issues/2787
var fname = path.basename(pathToMinBundle);
if(fname === 'plotly.min.js' || fname === 'plotly-mapbox.min.js') {
uglifyOptions.compress = {typeofs: false};
}

bundleStream
.pipe(minify(uglifyOptions))
.pipe(minify(constants.uglifyOptions))
.pipe(fs.createWriteStream(pathToMinBundle))
.on('finish', function() {
logger(pathToMinBundle);
Expand Down
20 changes: 20 additions & 0 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ module.exports = {
testContainerUrl: 'http://localhost:9010/',
testContainerHome: '/var/www/streambed/image_server/plotly.js',

uglifyOptions: {
ecma: 5,
mangle: true,
compress: {
// see full list of compress option
// https://github.com/fabiosantoscode/terser#compress-options
//
// need to turn off 'typeofs' to make mapbox-gl work in
// minified bundles, for more info see:
// https://github.com/plotly/plotly.js/issues/2787
typeofs: false
},
output: {
beautify: false,
ascii_only: true
},

sourceMap: false
},

licenseDist: [
'/**',
'* plotly.js v' + pkg.version,
Expand Down
15 changes: 3 additions & 12 deletions tasks/util/wrap_locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var path = require('path');
var minify = require('minify-stream');
var intoStream = require('into-stream');

var constants = require('./constants');

var prefix = 'Plotly.register(';
var suffix = ');';

Expand All @@ -23,19 +25,8 @@ module.exports = function wrap_locale(pathToInput, pathToOutput) {

var rawOut = prefix + data.substr(moduleStart, moduleEnd - moduleStart) + suffix;

var uglifyOptions = {
ecma: 5,
mangle: true,
compress: true,
output: {
beautify: false,
ascii_only: true
},
sourceMap: false
};

intoStream(rawOut)
.pipe(minify(uglifyOptions))
.pipe(minify(constants.uglifyOptions))
.pipe(fs.createWriteStream(pathToOutput))
.on('finish', function() {
logger(pathToOutput);
Expand Down

0 comments on commit 2a3afe7

Please sign in to comment.