Skip to content

Commit 20a2af0

Browse files
authored
Merge pull request #740 from plotly/partial-bundles
Introducing partial dist bundles
2 parents e020bb1 + 7a43781 commit 20a2af0

13 files changed

+477
-96
lines changed

.npmignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
build/*
2-
32
!build/plotcss.js
43
!build/ploticon.js
54
!build/README.md
65

76
devtools
87
test
9-
dist/extras/mathjax
8+
dist/extras
109

1110
circle.yml
1211
docker-compose.yml

lib/index-basic.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plotly = require('./core');
12+
13+
Plotly.register([
14+
require('./bar'),
15+
require('./pie')
16+
]);
17+
18+
module.exports = Plotly;

lib/index-cartesian.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plotly = require('./core');
12+
13+
Plotly.register([
14+
require('./bar'),
15+
require('./box'),
16+
require('./heatmap'),
17+
require('./histogram'),
18+
require('./histogram2d'),
19+
require('./histogram2dcontour'),
20+
require('./pie'),
21+
require('./contour'),
22+
require('./scatterternary')
23+
]);
24+
25+
module.exports = Plotly;

lib/index-geo.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plotly = require('./core');
12+
13+
Plotly.register([
14+
require('./scattergeo'),
15+
require('./choropleth')
16+
]);
17+
18+
module.exports = Plotly;

lib/index-gl2d.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plotly = require('./core');
12+
13+
Plotly.register([
14+
require('./scattergl'),
15+
require('./heatmapgl'),
16+
require('./contourgl')
17+
]);
18+
19+
module.exports = Plotly;

lib/index-gl3d.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plotly = require('./core');
12+
13+
Plotly.register([
14+
require('./scatter3d'),
15+
require('./surface'),
16+
require('./mesh3d')
17+
]);
18+
19+
module.exports = Plotly;

lib/index-mapbox.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plotly = require('./core');
12+
13+
Plotly.register([
14+
require('./scattermapbox')
15+
]);
16+
17+
module.exports = Plotly;

lib/index.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88

99
'use strict';
1010

11-
/*
12-
* This file is browserify'ed into a standalone 'Plotly' object.
13-
*/
11+
var Plotly = require('./core');
1412

15-
var Core = require('./core');
16-
17-
// Load all trace modules
18-
Core.register([
13+
Plotly.register([
1914
require('./bar'),
2015
require('./box'),
2116
require('./heatmap'),
@@ -33,4 +28,4 @@ Core.register([
3328
require('./scatterternary')
3429
]);
3530

36-
module.exports = Core;
31+
module.exports = Plotly;

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"preprocess": "node tasks/preprocess.js",
2525
"bundle": "node tasks/bundle.js",
2626
"header": "node tasks/header.js",
27-
"build": "npm run preprocess && npm run bundle && npm run header",
27+
"stats": "node tasks/stats.js",
28+
"build": "npm run preprocess && npm run bundle && npm run header && npm run stats",
2829
"cibuild": "npm run preprocess && node tasks/cibundle.js",
2930
"watch": "node tasks/watch_plotly.js",
3031
"lint": "eslint . || true",
@@ -95,6 +96,7 @@
9596
"fs-extra": "^0.30.0",
9697
"fuse.js": "^2.2.0",
9798
"glob": "^7.0.0",
99+
"gzip-size": "^3.0.0",
98100
"jasmine-core": "^2.4.1",
99101
"karma": "^1.1.0",
100102
"karma-browserify": "^5.0.1",

tasks/bundle.js

+62-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var fs = require('fs');
2+
var path = require('path');
23

34
var browserify = require('browserify');
45
var UglifyJS = require('uglify-js');
@@ -28,48 +29,76 @@ try {
2829
}
2930
catch(e) {
3031
throw new Error([
31-
'build/ is missing a or more files',
32+
'build/ is missing one or more files',
3233
'Please run `npm run preprocess` first'
3334
].join('\n'));
3435
}
3536

3637

3738
// Browserify plotly.js
38-
browserify(constants.pathToPlotlyIndex, {
39-
debug: DEV,
39+
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, {
4040
standalone: 'Plotly',
41-
transform: [compressAttributes]
42-
})
43-
.bundle(function(err, buf) {
44-
if(err) throw err;
45-
46-
// generate plotly.min.js
47-
if(!DEV) {
48-
fs.writeFile(
49-
constants.pathToPlotlyDistMin,
50-
UglifyJS.minify(buf.toString(), constants.uglifyOptions).code
51-
);
52-
}
53-
})
54-
.pipe(fs.createWriteStream(constants.pathToPlotlyDist));
55-
41+
debug: DEV,
42+
pathToMinBundle: constants.pathToPlotlyDistMin
43+
});
5644

5745
// Browserify the geo assets
58-
browserify(constants.pathToPlotlyGeoAssetsSrc, {
46+
_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, {
5947
standalone: 'PlotlyGeoAssets'
60-
})
61-
.bundle(function(err) {
62-
if(err) throw err;
63-
})
64-
.pipe(fs.createWriteStream(constants.pathToPlotlyGeoAssetsDist));
65-
48+
});
6649

6750
// Browserify the plotly.js with meta
68-
browserify(constants.pathToPlotlyIndex, {
69-
debug: DEV,
70-
standalone: 'Plotly'
71-
})
72-
.bundle(function(err) {
73-
if(err) throw err;
74-
})
75-
.pipe(fs.createWriteStream(constants.pathToPlotlyDistWithMeta));
51+
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDistWithMeta, {
52+
standalone: 'Plotly',
53+
debug: DEV
54+
});
55+
56+
// Browserify the plotly.js partial bundles
57+
constants.partialBundlePaths.forEach(function(pathObj) {
58+
_bundle(pathObj.index, pathObj.dist, {
59+
standalone: 'Plotly',
60+
debug: DEV,
61+
pathToMinBundle: pathObj.distMin
62+
});
63+
});
64+
65+
function _bundle(pathToIndex, pathToBundle, opts) {
66+
opts = opts || {};
67+
68+
// do we output a minified file?
69+
var pathToMinBundle = opts.pathToMinBundle,
70+
outputMinified = !!pathToMinBundle && !opts.debug;
71+
72+
var browserifyOpts = {};
73+
browserifyOpts.standalone = opts.standalone;
74+
browserifyOpts.debug = opts.debug;
75+
browserifyOpts.transform = outputMinified ? [compressAttributes] : [];
76+
77+
var b = browserify(pathToIndex, browserifyOpts),
78+
bundleWriteStream = fs.createWriteStream(pathToBundle);
79+
80+
bundleWriteStream.on('finish', function() {
81+
logger(pathToBundle);
82+
});
83+
84+
b.bundle(function(err, buf) {
85+
if(err) throw err;
86+
87+
if(outputMinified) {
88+
var minifiedCode = UglifyJS.minify(buf.toString(), constants.uglifyOptions).code;
89+
90+
fs.writeFile(pathToMinBundle, minifiedCode, function(err) {
91+
if(err) throw err;
92+
93+
logger(pathToMinBundle);
94+
});
95+
}
96+
})
97+
.pipe(bundleWriteStream);
98+
}
99+
100+
function logger(pathToOutput) {
101+
var log = 'ok ' + path.basename(pathToOutput);
102+
103+
console.log(log);
104+
}

0 commit comments

Comments
 (0)