Skip to content

Introducing partial dist bundles #740

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 12 commits into from
Jul 22, 2016
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
build/*

!build/plotcss.js
!build/ploticon.js
!build/README.md

devtools
test
dist/extras/mathjax
dist/extras

circle.yml
docker-compose.yml
Expand Down
18 changes: 18 additions & 0 deletions lib/index-basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Plotly = require('./core');
Copy link
Contributor

@rreusser rreusser Jul 22, 2016

Choose a reason for hiding this comment

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

I'd support a comment here noting that scatter is included in core. The first time I read through this, I was wondering if maybe bar or pie were cartesian and pulled in scatter through that (or some other magic). It's not that hard to figure out, but maybe just a nice sign-post if these are the template for creating your own. See: https://github.com/plotly/plotly.js/blob/master/src/plotly.js#L107-L108

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd vote 👎 on adding a comment here (in all the other index files) to avoid making them obsolete when we'll strip more things for the ./core.

I would prefer pointing users to the dist/README.md file where coreModules are listed:

image


Plotly.register([
require('./bar'),
require('./pie')
]);

module.exports = Plotly;
25 changes: 25 additions & 0 deletions lib/index-cartesian.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Plotly = require('./core');

Plotly.register([
require('./bar'),
require('./box'),
require('./heatmap'),
require('./histogram'),
require('./histogram2d'),
require('./histogram2dcontour'),
require('./pie'),
require('./contour'),
require('./scatterternary')
]);

module.exports = Plotly;
18 changes: 18 additions & 0 deletions lib/index-geo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Plotly = require('./core');

Plotly.register([
require('./scattergeo'),
require('./choropleth')
]);

module.exports = Plotly;
19 changes: 19 additions & 0 deletions lib/index-gl2d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Plotly = require('./core');

Plotly.register([
require('./scattergl'),
require('./heatmapgl'),
require('./contourgl')
]);

module.exports = Plotly;
19 changes: 19 additions & 0 deletions lib/index-gl3d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Plotly = require('./core');

Plotly.register([
require('./scatter3d'),
require('./surface'),
require('./mesh3d')
]);

module.exports = Plotly;
17 changes: 17 additions & 0 deletions lib/index-mapbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Plotly = require('./core');

Plotly.register([
require('./scattermapbox')
]);

module.exports = Plotly;
11 changes: 3 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@

'use strict';

/*
* This file is browserify'ed into a standalone 'Plotly' object.
*/
var Plotly = require('./core');

var Core = require('./core');

// Load all trace modules
Core.register([
Plotly.register([
require('./bar'),
require('./box'),
require('./heatmap'),
Expand All @@ -33,4 +28,4 @@ Core.register([
require('./scatterternary')
]);

module.exports = Core;
module.exports = Plotly;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"preprocess": "node tasks/preprocess.js",
"bundle": "node tasks/bundle.js",
"header": "node tasks/header.js",
"build": "npm run preprocess && npm run bundle && npm run header",
"stats": "node tasks/stats.js",
"build": "npm run preprocess && npm run bundle && npm run header && npm run stats",
"cibuild": "npm run preprocess && node tasks/cibundle.js",
"watch": "node tasks/watch_plotly.js",
"lint": "eslint . || true",
Expand Down Expand Up @@ -95,6 +96,7 @@
"fs-extra": "^0.30.0",
"fuse.js": "^2.2.0",
"glob": "^7.0.0",
"gzip-size": "^3.0.0",
"jasmine-core": "^2.4.1",
"karma": "^1.1.0",
"karma-browserify": "^5.0.1",
Expand Down
95 changes: 62 additions & 33 deletions tasks/bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var path = require('path');

var browserify = require('browserify');
var UglifyJS = require('uglify-js');
Expand Down Expand Up @@ -28,48 +29,76 @@ try {
}
catch(e) {
throw new Error([
'build/ is missing a or more files',
'build/ is missing one or more files',
'Please run `npm run preprocess` first'
].join('\n'));
}


// Browserify plotly.js
browserify(constants.pathToPlotlyIndex, {
debug: DEV,
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, {
standalone: 'Plotly',
transform: [compressAttributes]
})
.bundle(function(err, buf) {
if(err) throw err;

// generate plotly.min.js
if(!DEV) {
fs.writeFile(
constants.pathToPlotlyDistMin,
UglifyJS.minify(buf.toString(), constants.uglifyOptions).code
);
}
})
.pipe(fs.createWriteStream(constants.pathToPlotlyDist));

debug: DEV,
pathToMinBundle: constants.pathToPlotlyDistMin
});

// Browserify the geo assets
browserify(constants.pathToPlotlyGeoAssetsSrc, {
_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, {
standalone: 'PlotlyGeoAssets'
})
.bundle(function(err) {
if(err) throw err;
})
.pipe(fs.createWriteStream(constants.pathToPlotlyGeoAssetsDist));

});

// Browserify the plotly.js with meta
browserify(constants.pathToPlotlyIndex, {
debug: DEV,
standalone: 'Plotly'
})
.bundle(function(err) {
if(err) throw err;
})
.pipe(fs.createWriteStream(constants.pathToPlotlyDistWithMeta));
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDistWithMeta, {
standalone: 'Plotly',
debug: DEV
});

// Browserify the plotly.js partial bundles
constants.partialBundlePaths.forEach(function(pathObj) {
_bundle(pathObj.index, pathObj.dist, {
standalone: 'Plotly',
debug: DEV,
pathToMinBundle: pathObj.distMin
});
});

function _bundle(pathToIndex, pathToBundle, opts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought: what about moving this bundle function to its own file and exporting it? Then tasks/bundle.js would require and use _bundle. Which is all the same, except that it would make room for a standalone bundler script to also just use this function. As long as there were a stable, guaranteed location for this script, a standalone bundler repo would probably just require this script and not have to reimplement it.

Other alternative is that a standalone bundler would implement this and get required by plotly.js as a dev dependency to do the bundling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a thought: what about moving this bundle function to its own file and exporting it?

I thought about too. But I think it's worth spending more time perfecting our bundling scripts until we decide if/when/how we expose a bundler module.

Other alternative is that a standalone bundler would implement this and get required by plotly.js as a dev dependency to do the bundling.

This would get my vote at the moment.

opts = opts || {};

// do we output a minified file?
var pathToMinBundle = opts.pathToMinBundle,
outputMinified = !!pathToMinBundle && !opts.debug;

var browserifyOpts = {};
browserifyOpts.standalone = opts.standalone;
browserifyOpts.debug = opts.debug;
browserifyOpts.transform = outputMinified ? [compressAttributes] : [];

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

bundleWriteStream.on('finish', function() {
logger(pathToBundle);
});

b.bundle(function(err, buf) {
if(err) throw err;

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

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

logger(pathToMinBundle);
});
}
})
.pipe(bundleWriteStream);
}

function logger(pathToOutput) {
var log = 'ok ' + path.basename(pathToOutput);

console.log(log);
}
Loading