Skip to content

Commit

Permalink
revise bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Mar 12, 2024
1 parent 01db669 commit 2c3548a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
26 changes: 24 additions & 2 deletions tasks/bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ var tasks = [];
// Bundle plotly.js
tasks.push(function(done) {
_bundle(pathToPlotlyIndex, pathToPlotlyDist, {
pathToMinBundle: pathToPlotlyDistMin
}, function() {
prependFile.sync(pathToPlotlyDist, header, common.throwOnError);
prependFile.sync(pathToPlotlyDistMin, header, common.throwOnError);

done();
});
});

// Bundle plotly.min.js
tasks.push(function(done) {
_bundle(pathToPlotlyIndex, pathToPlotlyDistMin, {
minify: true,
}, function() {
prependFile.sync(pathToPlotlyDist, header, common.throwOnError);
prependFile.sync(pathToPlotlyDistMin, header, common.throwOnError);
Expand All @@ -46,7 +57,18 @@ tasks.push(function(done) {
// Bundle plotly.js-strict
tasks.push(function(done) {
_bundle(pathToPlotlyStrict, pathToPlotlyStrictDist, {
pathToMinBundle: pathToPlotlyStrictDistMin
}, function() {
prependFile.sync(pathToPlotlyStrictDist, header.replace('plotly.js', 'plotly.js (strict)'), common.throwOnError);
prependFile.sync(pathToPlotlyStrictDistMin, header.replace('plotly.js', 'plotly.js (strict - minified)'), common.throwOnError);

done();
});
});

// Bundle plotly.min.js-strict
tasks.push(function(done) {
_bundle(pathToPlotlyStrict, pathToPlotlyStrictDistMin, {
minify: true,
}, function() {
prependFile.sync(pathToPlotlyStrictDist, header.replace('plotly.js', 'plotly.js (strict)'), common.throwOnError);
prependFile.sync(pathToPlotlyStrictDistMin, header.replace('plotly.js', 'plotly.js (strict - minified)'), common.throwOnError);
Expand Down
34 changes: 27 additions & 7 deletions tasks/cibundle.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import runSeries from 'run-series';
import constants from './util/constants.js';
import _bundle from './util/bundle_wrapper.mjs';

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

// Bundle plotly.js and plotly.min.js
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, {
noCompressAttributes: true,
pathToMinBundle: constants.pathToPlotlyBuildMin
}, function() {
// Bundle the geo assets
// list of tasks to pass to run-series to not blow up
// memory consumption.
var tasks = [];

// Bundle plotly.js
tasks.push(function(done) {
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, {
noCompressAttributes: true,
}, done)
});

// Bundle plotly.min.js
tasks.push(function(done) {
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuildMin, {
minify: true,
noCompressAttributes: true,
}, done)
});

// Bundle the geo assets
tasks.push(function(done) {
_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, {
noPlugins: true,
standalone: 'PlotlyGeoAssets'
});
}, done)
});

runSeries(tasks, function(err) {
if(err) throw err;
});
18 changes: 15 additions & 3 deletions tasks/partial_bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,27 @@ export default function partialBundle(tasks, opts) {

tasks.push(function(done) {
var bundleOpts = {
deleteIndex: deleteIndex,
pathToMinBundle: distMin
deleteIndex: deleteIndex && !distMin,
};

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

if(dist) prependFile.sync(dist, headerDist, common.throwOnError);

done();
});
});

tasks.push(function(done) {
var bundleOpts = {
deleteIndex: deleteIndex,
minify: true,
};

_bundle(index, distMin, bundleOpts, function() {
var headerDistMin = header.replace('plotly.js', 'plotly.js (' + name + ' - minified)');

if(distMin) prependFile.sync(distMin, headerDistMin, common.throwOnError);

done();
Expand Down
27 changes: 6 additions & 21 deletions tasks/util/bundle_wrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ var basePlugins = esbuildConfig.plugins;
* Bundle options:
* - standalone {string}
* Additional option:
* - pathToMinBundle {string} path to destination minified bundle
* - noCompressAttributes {boolean} skip attribute meta compression?
* @param {function} cb callback
*
* Outputs one bundle (un-minified) file if opts.pathToMinBundle is omitted.
* Otherwise outputs two file: one un-minified bundle and one minified bundle.
*
* Logs basename of bundle when completed.
Expand All @@ -30,28 +28,15 @@ export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {
var config = {...esbuildConfig};

config.entryPoints = [pathToIndex];
config.outfile = pathToBundle || pathToMinBundle;
config.outfile = pathToBundle;
config.minify = !!opts.minify;

if(!opts.noCompressAttributes) {
config.plugins = basePlugins.concat([browserifyAdapter(transform)]);
}

if(opts.noPlugins) config.plugins = [];
var pathToMinBundle = opts.pathToMinBundle;
var pending = (pathToMinBundle && pathToBundle) ? 2 : 1;

config.minify = !!(pathToMinBundle && pending === 1);
config.outfile = pathToBundle || pathToMinBundle;
config.sourcemap = false;
build(config).then(function() {
if(pending === 2) {
config.minify = true;
config.outfile = pathToMinBundle;
// config.sourcemap = true;
build(config).then(function() {
if(cb) cb();
});
} else {
if(cb) cb();
}
});

await build(config);
if(cb) cb();
}

0 comments on commit 2c3548a

Please sign in to comment.