Skip to content

Commit 2a3afe7

Browse files
committed
turn off 'typeof' compress options for all minify steps
- for consistency and maintainability, this does lead to a few extra bytes though.
1 parent 7171bc4 commit 2a3afe7

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

tasks/util/browserify_wrapper.js

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

7+
var constants = require('./constants');
78
var compressAttributes = require('./compress_attributes');
89
var strictD3 = require('./strict_d3');
910

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

6061
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-
7962
bundleStream
80-
.pipe(minify(uglifyOptions))
63+
.pipe(minify(constants.uglifyOptions))
8164
.pipe(fs.createWriteStream(pathToMinBundle))
8265
.on('finish', function() {
8366
logger(pathToMinBundle);

tasks/util/constants.js

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

87+
uglifyOptions: {
88+
ecma: 5,
89+
mangle: true,
90+
compress: {
91+
// see full list of compress option
92+
// https://github.com/fabiosantoscode/terser#compress-options
93+
//
94+
// need to turn off 'typeofs' to make mapbox-gl work in
95+
// minified bundles, for more info see:
96+
// https://github.com/plotly/plotly.js/issues/2787
97+
typeofs: false
98+
},
99+
output: {
100+
beautify: false,
101+
ascii_only: true
102+
},
103+
104+
sourceMap: false
105+
},
106+
87107
licenseDist: [
88108
'/**',
89109
'* plotly.js v' + pkg.version,

tasks/util/wrap_locale.js

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

7+
var constants = require('./constants');
8+
79
var prefix = 'Plotly.register(';
810
var suffix = ');';
911

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

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

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-
3728
intoStream(rawOut)
38-
.pipe(minify(uglifyOptions))
29+
.pipe(minify(constants.uglifyOptions))
3930
.pipe(fs.createWriteStream(pathToOutput))
4031
.on('finish', function() {
4132
logger(pathToOutput);

0 commit comments

Comments
 (0)