Skip to content

Upgrade bundling #2187

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

Merged
merged 5 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"3d-view": "^2.0.0",
"@plotly/d3-sankey": "^0.5.0",
"alpha-shape": "^1.0.0",
"bubleify": "^1.0.0",
"color-rgba": "^1.1.1",
"convex-hull": "^1.0.3",
"country-regex": "^1.1.0",
Expand Down Expand Up @@ -86,6 +87,7 @@
"has-hover": "^1.0.1",
"mapbox-gl": "^0.22.0",
"matrix-camera-controller": "^2.1.3",
"minify-stream": "^1.1.0",
"mouse-change": "^1.4.0",
"mouse-event-offset": "^3.0.2",
"mouse-wheel": "^1.0.2",
Expand All @@ -109,6 +111,7 @@
"brfs": "^1.4.3",
"browserify": "^14.1.0",
"browserify-transform-tools": "^1.7.0",
"cross-spawn": "^5.1.0",
"deep-equal": "^1.0.1",
"ecstatic": "^2.1.0",
"eslint": "^3.17.1",
Expand Down Expand Up @@ -140,7 +143,6 @@
"read-last-lines": "^1.1.0",
"requirejs": "^2.3.1",
"through2": "^2.0.3",
"uglify-js": "^2.8.12",
"watchify": "^3.9.0",
"xml2js": "^0.4.16"
}
Expand Down
1 change: 1 addition & 0 deletions tasks/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ _bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, {
pathToMinBundle: constants.pathToPlotlyDistMin
});


// Browserify the geo assets
_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, {
standalone: 'PlotlyGeoAssets'
Expand Down
2 changes: 1 addition & 1 deletion tasks/stats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = require('path');
var fs = require('fs');
var spawn = require('child_process').spawn;
var spawn = require('cross-spawn');
Copy link
Contributor

Choose a reason for hiding this comment

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

Ha nice catch. That's for that spawn('npm', ['ls', '--json', '--only', 'prod']); statement below - which will be obsolete when we switch to npm@5 as the new package-lock.json file will do that same as the current dist/npm-ls.json.


var falafel = require('falafel');
var gzipSize = require('gzip-size');
Expand Down
40 changes: 20 additions & 20 deletions tasks/util/browserify_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var fs = require('fs');
var path = require('path');

var browserify = require('browserify');
var UglifyJS = require('uglify-js');
var bubleify = require('bubleify');
var minify = require('minify-stream');

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

/** Convenience browserify wrapper
Expand Down Expand Up @@ -46,30 +46,30 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts) {
}

var b = browserify(pathToIndex, browserifyOpts);
var bundleWriteStream = fs.createWriteStream(pathToBundle);

bundleWriteStream.on('finish', function() {
logger(pathToBundle);
if(opts.then) {
opts.then();
}
});
b.transform(bubleify, constants.bubleifyOptions);

b.bundle(function(err, buf) {
var bundleStream = b.bundle(function(err) {
if(err) throw err;
});

if(outputMinified) {
var minifiedCode = UglifyJS.minify(buf.toString(), constants.uglifyOptions).code;
minifiedCode = patchMinified(minifiedCode);

fs.writeFile(pathToMinBundle, minifiedCode, function(err) {
if(err) throw err;

if(outputMinified) {
bundleStream
.pipe(minify(constants.uglifyOptions))
.pipe(fs.createWriteStream(pathToMinBundle))
.on('finish', function() {
logger(pathToMinBundle);
});
}
})
.pipe(bundleWriteStream);
}

bundleStream
.pipe(fs.createWriteStream(pathToBundle))
.on('finish', function() {
logger(pathToBundle);
if(opts.then) {
opts.then();
}
});
};

function logger(pathToOutput) {
Expand Down
21 changes: 17 additions & 4 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,29 @@ module.exports = {
testContainerHome: '/var/www/streambed/image_server/plotly.js',

uglifyOptions: {
fromString: true,
mangle: true,
compress: {
warnings: false,
screw_ie8: true
warnings: false
},
output: {
beautify: false,
ascii_only: true
}
},
sourceMap: false
},

bubleifyOptions: {
target: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. We have to target browsers waaaaaaaay older than that. Can bubleify guarantee to output code that IE11 understands?

Copy link
Contributor Author

@dy dy Nov 28, 2017

Choose a reason for hiding this comment

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

@etpinard that is the best bubleify can do, it is targeted only for ES6 → ES5, not ES5 → ES3.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Well that won't work then. plotly.js needs to be pure ES5.

Copy link
Contributor Author

@dy dy Nov 29, 2017

Choose a reason for hiding this comment

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

@etpinard that is pure ES5, same as what we have now. target flag only indicates what new ES6 features are supported by target environment to avoid their handling, eg. some browsers have Object.assign or arrow functions, but do not do power a ** b etc, so since we indicate oldest target available in buble, we make sure we get pure ES5.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we put these config options in the package.json instead, so that all consumers bundling with browserify or webpack+ify-loader get the same results as us in our dist/?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the output bundle be minified by plain-old uglify-js? e.g. does

browserify -t bubleify src/plotly.js | uglify-js > bundle.js

work?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a big fan of this target option. I find it pretty confusing. Could we instead manually list all the transforms we want turned on?

chrome: 48,
firefox: 44,
edge: 12
},
transforms: {
arrow: true,
defaultParameter: false,
dangerousForOf: true,
},
sourceMap: false
},

licenseDist: [
Expand Down
22 changes: 0 additions & 22 deletions tasks/util/patch_minified.js

This file was deleted.