Skip to content

Commit 96a5e7e

Browse files
committed
revise bundles
1 parent 01db669 commit 96a5e7e

File tree

4 files changed

+68
-33
lines changed

4 files changed

+68
-33
lines changed

tasks/bundle.mjs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,18 @@ var tasks = [];
3434
// Bundle plotly.js
3535
tasks.push(function(done) {
3636
_bundle(pathToPlotlyIndex, pathToPlotlyDist, {
37-
pathToMinBundle: pathToPlotlyDistMin
3837
}, function() {
3938
prependFile.sync(pathToPlotlyDist, header, common.throwOnError);
39+
40+
done();
41+
});
42+
});
43+
44+
// Bundle plotly.min.js
45+
tasks.push(function(done) {
46+
_bundle(pathToPlotlyIndex, pathToPlotlyDistMin, {
47+
minify: true,
48+
}, function() {
4049
prependFile.sync(pathToPlotlyDistMin, header, common.throwOnError);
4150

4251
done();
@@ -46,9 +55,18 @@ tasks.push(function(done) {
4655
// Bundle plotly.js-strict
4756
tasks.push(function(done) {
4857
_bundle(pathToPlotlyStrict, pathToPlotlyStrictDist, {
49-
pathToMinBundle: pathToPlotlyStrictDistMin
5058
}, function() {
5159
prependFile.sync(pathToPlotlyStrictDist, header.replace('plotly.js', 'plotly.js (strict)'), common.throwOnError);
60+
61+
done();
62+
});
63+
});
64+
65+
// Bundle plotly.min.js-strict
66+
tasks.push(function(done) {
67+
_bundle(pathToPlotlyStrict, pathToPlotlyStrictDistMin, {
68+
minify: true,
69+
}, function() {
5270
prependFile.sync(pathToPlotlyStrictDistMin, header.replace('plotly.js', 'plotly.js (strict - minified)'), common.throwOnError);
5371

5472
done();

tasks/cibundle.mjs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import runSeries from 'run-series';
12
import constants from './util/constants.js';
23
import _bundle from './util/bundle_wrapper.mjs';
34

@@ -11,14 +12,33 @@ import _bundle from './util/bundle_wrapper.mjs';
1112
* - plotly.min.js bundle in build/ (for minified_bundle test)
1213
*/
1314

14-
// Bundle plotly.js and plotly.min.js
15-
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, {
16-
noCompressAttributes: true,
17-
pathToMinBundle: constants.pathToPlotlyBuildMin
18-
}, function() {
19-
// Bundle the geo assets
15+
// list of tasks to pass to run-series to not blow up
16+
// memory consumption.
17+
var tasks = [];
18+
19+
// Bundle plotly.js
20+
tasks.push(function(done) {
21+
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, {
22+
noCompressAttributes: true,
23+
}, done)
24+
});
25+
26+
// Bundle plotly.min.js
27+
tasks.push(function(done) {
28+
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuildMin, {
29+
minify: true,
30+
noCompressAttributes: true,
31+
}, done)
32+
});
33+
34+
// Bundle the geo assets
35+
tasks.push(function(done) {
2036
_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, {
2137
noPlugins: true,
2238
standalone: 'PlotlyGeoAssets'
23-
});
39+
}, done)
40+
});
41+
42+
runSeries(tasks, function(err) {
43+
if(err) throw err;
2444
});

tasks/partial_bundle.mjs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,27 @@ export default function partialBundle(tasks, opts) {
5555

5656
tasks.push(function(done) {
5757
var bundleOpts = {
58-
deleteIndex: deleteIndex,
59-
pathToMinBundle: distMin
58+
deleteIndex: deleteIndex && !distMin,
6059
};
6160

6261
_bundle(index, dist, bundleOpts, function() {
6362
var headerDist = header.replace('plotly.js', 'plotly.js (' + name + ')');
64-
var headerDistMin = header.replace('plotly.js', 'plotly.js (' + name + ' - minified)');
6563

6664
if(dist) prependFile.sync(dist, headerDist, common.throwOnError);
65+
66+
done();
67+
});
68+
});
69+
70+
tasks.push(function(done) {
71+
var bundleOpts = {
72+
deleteIndex: deleteIndex,
73+
minify: true,
74+
};
75+
76+
_bundle(index, distMin, bundleOpts, function() {
77+
var headerDistMin = header.replace('plotly.js', 'plotly.js (' + name + ' - minified)');
78+
6779
if(distMin) prependFile.sync(distMin, headerDistMin, common.throwOnError);
6880

6981
done();

tasks/util/bundle_wrapper.mjs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ var basePlugins = esbuildConfig.plugins;
1515
* Bundle options:
1616
* - standalone {string}
1717
* Additional option:
18-
* - pathToMinBundle {string} path to destination minified bundle
1918
* - noCompressAttributes {boolean} skip attribute meta compression?
2019
* @param {function} cb callback
2120
*
22-
* Outputs one bundle (un-minified) file if opts.pathToMinBundle is omitted.
2321
* Otherwise outputs two file: one un-minified bundle and one minified bundle.
2422
*
2523
* Logs basename of bundle when completed.
@@ -30,28 +28,15 @@ export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {
3028
var config = {...esbuildConfig};
3129

3230
config.entryPoints = [pathToIndex];
33-
config.outfile = pathToBundle || pathToMinBundle;
31+
config.outfile = pathToBundle;
32+
config.minify = !!opts.minify;
33+
3434
if(!opts.noCompressAttributes) {
3535
config.plugins = basePlugins.concat([browserifyAdapter(transform)]);
3636
}
3737

3838
if(opts.noPlugins) config.plugins = [];
39-
var pathToMinBundle = opts.pathToMinBundle;
40-
var pending = (pathToMinBundle && pathToBundle) ? 2 : 1;
41-
42-
config.minify = !!(pathToMinBundle && pending === 1);
43-
config.outfile = pathToBundle || pathToMinBundle;
44-
config.sourcemap = false;
45-
build(config).then(function() {
46-
if(pending === 2) {
47-
config.minify = true;
48-
config.outfile = pathToMinBundle;
49-
// config.sourcemap = true;
50-
build(config).then(function() {
51-
if(cb) cb();
52-
});
53-
} else {
54-
if(cb) cb();
55-
}
56-
});
39+
40+
await build(config);
41+
if(cb) cb();
5742
}

0 commit comments

Comments
 (0)