Skip to content

Commit 1f1e47c

Browse files
committed
undo 'typeofs' compress for min bundles that include mapbox-gl
... and run full compress otherwise.
1 parent 32e6984 commit 1f1e47c

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

tasks/util/browserify_wrapper.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var path = require('path');
44
var browserify = require('browserify');
55
var minify = require('minify-stream');
66

7-
var constants = require('./constants');
87
var compressAttributes = require('./compress_attributes');
98
var strictD3 = require('./strict_d3');
109

@@ -45,7 +44,7 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
4544
}
4645

4746
var b = browserify(pathToIndex, browserifyOpts);
48-
var pending = opts.pathToMinBundle ? 2 : 1;
47+
var pending = pathToMinBundle ? 2 : 1;
4948

5049
function done() {
5150
if(cb && --pending === 0) cb(null);
@@ -58,9 +57,27 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
5857
}
5958
});
6059

61-
if(opts.pathToMinBundle) {
60+
if(pathToMinBundle) {
61+
var uglifyOptions = {
62+
ecma: 5,
63+
mangle: true,
64+
compress: true,
65+
output: {
66+
beautify: false,
67+
ascii_only: true
68+
},
69+
sourceMap: false
70+
};
71+
72+
// need this to make mapbox-gl work in minified bundles
73+
// see https://github.com/plotly/plotly.js/issues/2787
74+
var fname = path.basename(pathToMinBundle);
75+
if(fname === 'plotly.min.js' || fname === 'plotly-mapbox.min.js') {
76+
uglifyOptions.compress = {typeofs: false};
77+
}
78+
6279
bundleStream
63-
.pipe(minify(constants.uglifyOptions))
80+
.pipe(minify(uglifyOptions))
6481
.pipe(fs.createWriteStream(pathToMinBundle))
6582
.on('finish', function() {
6683
logger(pathToMinBundle);

tasks/util/constants.js

-13
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,6 @@ module.exports = {
8484
testContainerUrl: 'http://localhost:9010/',
8585
testContainerHome: '/var/www/streambed/image_server/plotly.js',
8686

87-
uglifyOptions: {
88-
mangle: true,
89-
// the compress flag break mapbox-gl,
90-
// TODO find a way to only skip compression on mapbox-gl files
91-
compress: false,
92-
output: {
93-
beautify: false,
94-
ascii_only: true
95-
},
96-
97-
sourceMap: false
98-
},
99-
10087
licenseDist: [
10188
'/**',
10289
'* plotly.js v' + pkg.version,

tasks/util/wrap_locale.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ var path = require('path');
44
var minify = require('minify-stream');
55
var intoStream = require('into-stream');
66

7-
var constants = require('./constants');
8-
97
var prefix = 'Plotly.register(';
108
var suffix = ');';
119

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

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

26+
var uglifyOptions = {
27+
ecma: 5,
28+
mangle: true,
29+
compress: true,
30+
output: {
31+
beautify: false,
32+
ascii_only: true
33+
},
34+
sourceMap: false
35+
};
36+
2837
intoStream(rawOut)
29-
.pipe(minify(constants.uglifyOptions))
38+
.pipe(minify(uglifyOptions))
3039
.pipe(fs.createWriteStream(pathToOutput))
3140
.on('finish', function() {
3241
logger(pathToOutput);

0 commit comments

Comments
 (0)